From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796122287; b=wVxmy/IZAPoZFLjGPPj4kCoOHuNVUxSC21xBmVRp/0ErTeUq3WFf71YWCOABhukHNtvQ 5vt4VQwLC8TYTPbxqzWUPvyUpCxvzBzpMfiCoQPugOgIpTBpIByaZUVFEdXKQAnPNDCvP cx5FyhOuogNhnm2GJcyLR4Eai0BDXv5RywUkSl6SuKNRwsluAPiTsvXU97A21ycMqhbUY 2wWSxxQizj520ERCZkmwj+ZU+YI/VtLKztYyji5mT0PEW4APnc+PF/HHQ8vz1ocAsHOYv NILvIa0DMzjoNEc47VM6NcDlqqaXLcqSYhMbg9Tz13yaIO54Jp8/0lk7KOfNQHO3N3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796122287; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:From:Content-Language:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-TM-AS-GCONF: X-Proofpoint-Reinject:X-Proofpoint-Spam-Details-Enc: X-Authority-Analysis:X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Info:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=QIXpbonsbPxrLyjsnUIze5wsSI5xP6N/XU6KFsVtW7g=; b=trjsgcpotztdBXWTzYJPlbMElZOHR3DRCCVJEo4EGQUHGlAYMw4p/9rY7fBULoXqXM7F pkJus9m79EN+Obmse30FII0/JqzWmu2HgLGMWxMk+B5mhyNZclMx6HU4PG/ssiTyvLC9P FQLNVF460MCZR/ap3FrHsW74TT3NCqyS5lyqzQ2gGCw00LbbEaXUtMuNIhg43IHSKgJ+S D4RXEPuG71duwiT/ui9pup9GN7fSG5T/i+59S9wWPXII64tqo2YxGiLKnjWqc0DZ+9/+/ H6qZNby6CZmpB3nUlz6RMlBsTQyj+FnXPlyWNVMekACzXOQCRPyQjk7yvSdgD+cEYhw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=frIdmYOF; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68011606A31A for ; Tue, 1 Dec 2026 10:51:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 68011606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=frIdmYOF Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1AYnZo316840; Tue, 1 Dec 2026 10:50:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=QIXpbo nsbPxrLyjsnUIze5wsSI5xP6N/XU6KFsVtW7g=; b=frIdmYOFJx/3QKQhCW7+0t bqLKUKtYVp4J5RJfkqJL+7OiGPznSkN9BZk6vCa3/L8nn+vfuXEIVEbAkYGeKXVd cpYn9Z83qpYb4gEVxygBXba3iOnudCqT8hOdP+Lq7r6MNOETPwkcOl8U3YGhUV6f 9T695IbSh2Rlw4PvXoOE1evEATuEguwZDfRUeKCrBuQ5zxjv9lx6VUI1qk1gRG9O yhidCj8Z+Kw3tCpB+zPCESgV4w/kuYmIXFA2sgU0+7rjbmmhwaT89BqFv5ebnRUd LbUo9TZcOy+slS8N1s1zURxiQki7+fKUQyH6aEXmuC/nqpInI6s219Y47j3yjdiA == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7nchkshm-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 10:50:56 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1AYMVi1352399; Tue, 1 Dec 2026 10:50:55 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j9ujng85a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 10:50:55 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B1Aop2a46006760 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Dec 2026 10:50:52 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6C522004B; Tue, 1 Dec 2026 10:50:51 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0D5FE20043; Tue, 1 Dec 2026 10:50:47 +0000 (GMT) Received: from [9.124.211.228] (unknown [9.124.211.228]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 1 Dec 2026 10:50:46 +0000 (GMT) Message-ID: Date: Tue, 1 Dec 2026 16:20:45 +0530 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 5/6] powerpc/cacheinfo: Move to generic cacheinfo To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, christophe.leroy@csgroup.eu Cc: ritesh.list@gmail.com, tim.c.chen@linux.intel.com, yu.c.chen@intel.com, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, johan@kernel.org, sudeep.holla@kernel.org, peterz@infradead.org, tglx@kernel.org, kprateek.nayak@amd.com, srikar@linux.ibm.com, maddy@linux.ibm.com References: <20261127152242.306333-1-sshegde@linux.ibm.com> <20261127152242.306333-6-sshegde@linux.ibm.com> From: Shrikanth Hegde Content-Language: en-US In-Reply-To: <20261127152242.306333-6-sshegde@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA0MiBTYWx0ZWRfXy1t/6jtnF32z LKtUzsemffZdeAYIbkNa19UnPAICY8mbqcEGin4WgKfs6AfjWKif4OpSTrUKQlwEOuqV+0w8Nsp U2w0jUWh7UWKdtLERX/ps3+v0U+WmM0ubIzl4izu8RicWW4e9ouKhZ6IwOxCC6BrLx1sWk0ji2J sWFlXHwn/F7UpUwHSm8aMcgL9oAWBhWVsk6j8tA39RwLfdD93Y01h0/55fI4BmvVtZ5E0fhCZtO fLyGsE6lT6t2CsUwuHQP/C6xZqRWix/FqzmPVJRTzQjUzx0tNuqxob4KcaoV21pkXAf0el1HVFD RqvLO+Rht3lbj+hCcxm+nxL4X+cjIGAD3PJwc5Lj2AG1OdNhQ+at/6Fq1nTo7begva0NqJBemGS VHkTN2XuGVIxhMtBTM9rqafnDyQ6I+vb8+1+UI/3Y7l8XXTuGGrwozSI+2njVg6Vek2MYFnRssQ bdEMQwrV1WR/xTaUBUA== X-Authority-Analysis: v=2.4 cv=Tt5zFzXh c=1 sm=1 tr=0 ts=6b0ea691 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=c92rfblmAAAA:8 a=VnNF1IyMAAAA:8 a=50-kmMmZDRz5Il6b_Q8A:9 a=QEXdDO2ut3YA:10 a=GvGzcOZaWPEFPQC_NcjD:22 X-Proofpoint-ORIG-GUID: nYDq5054Fj1uzg5bXhWN0ERetdH1yaaV X-Proofpoint-GUID: r5j79wsbYFgkIK05461yCLwKYDN9K6ZP X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA0MiBTYWx0ZWRfX//6mgiw9LNih oHU8sEjkTheP9wij6x+KoxQ1JVMW5q7KlIZUoPJ75HCgzDXgNo/7KwCWCRHIS++AYpqfUjJciSb xXDZPJAMrtRKZybLAJ3cufjOQ3DEp1c= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_02,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1015 adultscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010042 Posting reply to shashiko review at https://sashiko.dev/#/patchset/20261127152242.306333-1-sshegde%40linux.ibm.com Summary: Only two are worth fixing at this moment. Christophe, Please see below a possible issue on 85xx. Would like your comments on it. > +int cacheinfo_get_arch_id(unsigned int cpu, unsigned int level, > + unsigned int *id) > { > + const struct cpumask *mask = NULL; > + mask = per_cpu(thread_group_l1_cache_map, cpu); > + mask = per_cpu(thread_group_l2_cache_map, cpu); > + mask = per_cpu(thread_group_l3_cache_map, cpu); > + if (!mask || cpumask_empty(mask)) > + return -ENOENT; Review: ======= Does falling back to -ENOENT whenever thread-group masks are not used cause quadratic device-tree scans during boot and Live Partition Mobility rebuilds? Reply: ====== Possible. But this happens during online or bootup time. Improvements can be taken up post the initial series. > + *id = cpumask_first(mask); > + if (*id >= nr_cpu_ids) > + return -ENOENT; > Review: ======= When thread_group_shares_l2 or thread_group_shares_l3 is false (such as on POWER8/POWER9 topologies without ibm,thread-groups property 2), can returning -ENOENT here produce inconsistent L2/L3 cache IDs across pSeries DLPAR operations? On -ENOENT, cache_of_set_id() sets leaf->id and CACHE_ID from the minimum hardware ID among CPU nodes currently attached in the device tree that reference the cache node. When multiple CPU nodes share an L2 or L3 cache node and the lowest-hwid CPU node is added via dlpar_cpu_add() or detached via dlpar_cpu_remove() (where pseries_cpuhp_detach_nodes() keeps shared cache nodes attached when pseries_cpuhp_cache_use_count(dn) > 1), newly populated leaves compute a different min_id from the id retained by already-online CPUs sharing that cache node. Because cache_leaves_are_shared() compares only leaf->id when CACHE_ID is set and ignores fw_token, CPUs sharing the same cache node no longer match, splitting shared_cpu_map and miscalculating per_cpu_data_slice_size and scheduler llc_bytes. Reply: ====== For the current topologies support DLPAR, cache heirarchy doesn't spawn across nodes. CPU DLPAR operates on a complete firmware CPU node, which represents the full core. Cache sharing is within that core. On Power11, ibm,thread-groups further divides the eight threads into the two physical cache-sharing groups 0,2,4,6 and 1,3,5,7, for which the architecture hook supplies explicit IDs. On systems without thread-group information, I am not sure if DLPAR is possible. Even if it is, since full core is removed/added and leaves don't span across a node, I don't think there will be a leave retaining old minimal firmware based ID. So I don't this this is an issue. > -static void remove_cache_dir(struct cache_dir *cache_dir) > +int populate_cache_leaves(unsigned int cpu) > { > - remove_index_dirs(cache_dir); > + struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu); > + struct cacheinfo *leaf = ci->info_list; > + struct device_node *next; > + struct device_node *np; > + unsigned int index = 0; > + unsigned int level = 1; > > - /* Remove cache dir from sysfs */ > - kobject_del(cache_dir->kobj); > + np = of_get_cpu_node(cpu, NULL); > + if (!np) > + return -ENOENT; > > - kobject_put(cache_dir->kobj); > + for (;;) { > + bool unified = of_property_read_bool(np, "cache-unified"); > Review: ======= Does checking only "cache-unified" break cacheinfo and CPU online on PowerPC device trees whose unified L2/L3 cache nodes omit that property? Unlike of_count_cache_leaves() in drivers/base/cacheinfo.c, which also treats a node with "cache-size" as unified, powerpc_cache_leaves() and populate_cache_leaves() emit two leaves (CACHE_TYPE_DATA and CACHE_TYPE_INST) at the same level > 1 whenever "cache-unified" is absent. Many in-tree PowerPC 44x, 85xx, and QorIQ device trees (for example arch/powerpc/boot/dts/xpedite5370.dts) describe unified L2 caches using "cache-size" and "cache-line-size" without "cache-unified". When two leaves share a level > 1, cache_setup_of_node() advances to the next cache node on every non-L1 leaf: drivers/base/cacheinfo.c:cache_setup_of_node() { while (index < cache_leaves(cpu)) { this_leaf = per_cpu_cacheinfo_idx(cpu, index); if (this_leaf->level != 1) { struct device_node *prev __free(device_node) = np; np = of_find_next_cache_node(np); if (!np) break; } ... index++; } if (index != cache_leaves(cpu)) /* not all OF nodes populated */ return -ENOENT; } Advancing np twice for a single L2 node exhausts the cache node chain and returns -ENOENT, which rolls back cacheinfo sysfs creation for all CPUs at boot and causes runtime CPU online operations to fail. Reply: Possible if such device tree structures exists. Christophe, or anyone having 85xx, 44xx can you please try the series and see if cacheinfo structures are compatible? If not, could you please try with the below diff? --- diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c index e77e613bcf44..fa475e059705 100644 --- a/arch/powerpc/kernel/cacheinfo.c +++ b/arch/powerpc/kernel/cacheinfo.c @@ -52,17 +52,23 @@ static void powerpc_cache_leaf_init(struct cacheinfo *leaf, leaf->type = type; } + /* * A node carrying cache-unified represents one unified cache leaf. * Other nodes represent separate data and instruction cache leaves. * - * Cache property availability does not determine whether a leaf - * exists. Missing optional properties are handled by generic - * cacheinfo. + * Few older powerpc implementation may have unified cache without + * explicit cache-unified and only specify cache-size. */ +static bool powerpc_cache_is_unified(struct device_node *np) +{ + return of_property_read_bool(np, "cache-unified") || + of_property_read_bool(np, "cache-size"); +} + static unsigned int powerpc_cache_leaves(struct device_node *np) { - return of_property_read_bool(np, "cache-unified") ? 1 : 2; + return powerpc_cache_is_unified(np) ? 1 : 2; } int init_cache_level(unsigned int cpu) @@ -112,7 +118,7 @@ int populate_cache_leaves(unsigned int cpu) return -ENOENT; for (;;) { - bool unified = of_property_read_bool(np, "cache-unified"); + bool unified = powerpc_cache_is_unified(np); if (unified) { if (index >= ci->num_leaves) > - kfree(cache_dir); > -} > + if (unified) { > + if (index >= ci->num_leaves) > + goto err; > ... > +static void dlpar_invalidate_cpu_cacheinfo(struct device_node *dn) > +{ > + const __be32 *intserv; > + unsigned int cpu; > + int len, nthreads, i; > + u32 thread; > + > + intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", &len); > + if (!intserv) > + return; > + > + nthreads = len / sizeof(u32); > + > + for (i = 0; i < nthreads; i++) { > + thread = be32_to_cpu(intserv[i]); > + for_each_present_cpu(cpu) { > + if (get_hard_smp_processor_id(cpu) != thread) > + continue; > + > + cacheinfo_invalidate_cpu(cpu); > + break; > + } > + } > +} Review: ======= Can a boot-present CPU thread that was already offline when its core was removed via dlpar_cpu_remove() retain a stale get_cpu_device(cpu)->of_node and fail to come online when re-added? At boot, topology_init() -> register_cpu() populates cpu->dev.of_node for every present thread, even if the thread stays offline (for example under reduced SMT or maxcpus). During dlpar_cpu_remove(), dlpar_offline_cpu() skips threads that are not online, so unregister_cpu_of_node() never runs to release and clear dev->of_node. When a new core is later added with dlpar_cpu_add() reusing those logical CPU IDs, register_cpu_of_node() sees a non-NULL dev->of_node and leaves the detached node in place: arch/powerpc/kernel/sysfs.c:register_cpu_of_node() { struct device *dev = get_cpu_device(cpu); if (!dev->of_node) dev->of_node = of_get_cpu_node(cpu, NULL); return 0; } When that thread is brought online, init_cache_level() and populate_cache_leaves() walk the new attached CPU node via of_get_cpu_node(cpu, NULL), while cache_setup_of_node() walks the stale detached dev->of_node via of_cpu_device_node_get(cpu). Looking up the detached L2 phandle in of_find_next_cache_node() then returns NULL, failing cache_setup_of_node() with -ENOENT and aborting dlpar_cpu_add(). Reply: Yes. Good catch. register_cpu() associates dev->of_node for every present CPU, including threads that are offline at boot. Such a thread is skipped by dlpar_offline_cpu(), so it does not execute unregister_cpu_of_node() and can retain a reference to the CPU node being detached. So, I am thinking below to address it. Just check it again at online and fix it if it is different. diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c index 44ae42989b6a..57c0e015a684 100644 --- a/arch/powerpc/kernel/sysfs.c +++ b/arch/powerpc/kernel/sysfs.c @@ -836,6 +836,7 @@ static void remove_idle_spurr_file(struct device *s) static int register_cpu_of_node(unsigned int cpu) { struct device *dev = get_cpu_device(cpu); + struct device_node *np; if (!dev) return -ENODEV; @@ -845,12 +846,18 @@ static int register_cpu_of_node(unsigned int cpu) * register_cpu(). DLPAR-added and re-onlined CPUs may not have * the OF node associated with the CPU device yet. */ - if (!dev->of_node) - dev->of_node = of_get_cpu_node(cpu, NULL); - - if (!dev->of_node) + np = of_get_cpu_node(cpu, NULL); + if (!np) return -ENOENT; + /* A previously offline CPU may hold older device node referrence */ + if (dev->of_node != np) { + of_node_put(dev->of_node); + dev->of_node = np; + } else { + of_node_put(np); + } + return 0; }