From nobody Sun Feb 8 12:32:18 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 B60B1212B21; Fri, 10 Jan 2025 16:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736525462; cv=none; b=Z8DCuQ5tixkVLATGBMCfrPYYxGEFWrqamUA8fkaDK0jCRL4SeTBmpmOJHfI7a40VKOETOsrq66ByeW290oWMiTAeQeAqFyBRZ27Y7YVJIjrMyjo11P1bgWHk5sKH9zGc8hN0tG9RtLMEwxQhPdejRD/Nb6378thByrIOkR5k/mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736525462; c=relaxed/simple; bh=I86OdE3kOZHcryMKY1mnL6NG++435v7MmEkzYpOOFJo=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=N5yrQbkvIqfrGXcRBMCmRhWkitzunR38ZemzCkr0QpD3gtqPz7yImrfwC2YlU3KjtP1FBupMm4imo/OI1KY5b3sLR7cBLPemcX3laApO6uZ6pXi902y2pPwfB0BK5Cy4RnrMXj71+6gYqjOfCI2qP1fjXQfNikzjlWYrUI8zAaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4YV66w15Tmz6L4xp; Sat, 11 Jan 2025 00:09:44 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id DDA1A1401DC; Sat, 11 Jan 2025 00:10:58 +0800 (CST) Received: from a2303103017.china.huawei.com (10.203.177.99) by frapeml500003.china.huawei.com (7.182.85.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 10 Jan 2025 17:10:58 +0100 From: Alireza Sanaee To: , , CC: , , , , , Subject: [PATCH] arm64: of: handle multiple threads in ARM cpu node Date: Fri, 10 Jan 2025 16:10:57 +0000 Message-ID: <20250110161057.445-1-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: lhrpeml100010.china.huawei.com (7.191.174.197) To frapeml500003.china.huawei.com (7.182.85.28) Content-Type: text/plain; charset="utf-8" Update `of_parse_and_init_cpus` to parse reg property of CPU node as an array based as per spec for SMT threads. Spec v0.4 Section 3.8.1: The value of reg is a that defines a unique CPU/thread id for the CPU/threads represented by the CPU node. **If a CPU supports more than one thread (i.e. multiple streams of execution) the reg property is an array with 1 element per thread**. The address-cells on the /cpus node specifies how many cells each element of the array takes. Software can determine the number of threads by dividing the size of reg by the parent node's address-cells. An accurate example of 1 core with 2 SMTs: cpus { #size-cells =3D <0x00>; #address-cells =3D <0x01>; cpu@0 { phandle =3D <0x8000>; **reg =3D <0x00 0x01>;** enable-method =3D "psci"; compatible =3D "arm,cortex-a57"; device_type =3D "cpu"; }; }; Instead of: cpus { #size-cells =3D <0x00>; #address-cells =3D <0x01>; cpu@0 { phandle =3D <0x8000>; reg =3D <0x00>; enable-method =3D "psci"; compatible =3D "arm,cortex-a57"; device_type =3D "cpu"; }; cpu@1 { phandle =3D <0x8001>; reg =3D <0x01>; enable-method =3D "psci"; compatible =3D "arm,cortex-a57"; device_type =3D "cpu"; }; }; which is **NOT** accurate. Signed-off-by: Alireza Sanaee --- arch/arm64/kernel/smp.c | 74 +++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 3b3f6b56e733..8dd3b3c82967 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -689,53 +689,61 @@ static void __init acpi_parse_and_init_cpus(void) static void __init of_parse_and_init_cpus(void) { struct device_node *dn; + u64 hwid; + u32 tid; =20 for_each_of_cpu_node(dn) { - u64 hwid =3D of_get_cpu_hwid(dn, 0); + tid =3D 0; =20 - if (hwid & ~MPIDR_HWID_BITMASK) - goto next; + while (1) { + hwid =3D of_get_cpu_hwid(dn, tid++); + if (hwid =3D=3D ~0ULL) + break; =20 - if (is_mpidr_duplicate(cpu_count, hwid)) { - pr_err("%pOF: duplicate cpu reg properties in the DT\n", - dn); - goto next; - } + if (hwid & ~MPIDR_HWID_BITMASK) + goto next; =20 - /* - * The numbering scheme requires that the boot CPU - * must be assigned logical id 0. Record it so that - * the logical map built from DT is validated and can - * be used. - */ - if (hwid =3D=3D cpu_logical_map(0)) { - if (bootcpu_valid) { - pr_err("%pOF: duplicate boot cpu reg property in DT\n", - dn); + if (is_mpidr_duplicate(cpu_count, hwid)) { + pr_err("%pOF: duplicate cpu reg properties in the DT\n", + dn); goto next; } =20 - bootcpu_valid =3D true; - early_map_cpu_to_node(0, of_node_to_nid(dn)); - /* - * cpu_logical_map has already been - * initialized and the boot cpu doesn't need - * the enable-method so continue without - * incrementing cpu. + * The numbering scheme requires that the boot CPU + * must be assigned logical id 0. Record it so that + * the logical map built from DT is validated and can + * be used. */ - continue; - } + if (hwid =3D=3D cpu_logical_map(0)) { + if (bootcpu_valid) { + pr_err("%pOF: duplicate boot cpu reg property in DT\n", + dn); + goto next; + } + + bootcpu_valid =3D true; + early_map_cpu_to_node(0, of_node_to_nid(dn)); + + /* + * cpu_logical_map has already been + * initialized and the boot cpu doesn't need + * the enable-method so continue without + * incrementing cpu. + */ + continue; + } =20 - if (cpu_count >=3D NR_CPUS) - goto next; + if (cpu_count >=3D NR_CPUS) + goto next; =20 - pr_debug("cpu logical map 0x%llx\n", hwid); - set_cpu_logical_map(cpu_count, hwid); + pr_debug("cpu logical map 0x%llx\n", hwid); + set_cpu_logical_map(cpu_count, hwid); =20 - early_map_cpu_to_node(cpu_count, of_node_to_nid(dn)); + early_map_cpu_to_node(cpu_count, of_node_to_nid(dn)); next: - cpu_count++; + cpu_count++; + } } } =20 --=20 2.43.0