From nobody Fri Sep 25 12:38:03 2026 Received: from mail-wm2-f12.google.com (mail-wm2-f12.google.com [74.125.225.140]) (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 95E0438F93B for ; Sat, 12 Sep 2026 19:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242965; cv=none; b=dk2lSZAFgVUXJ0OlQouB8zB9J5vq8hcyWc/0WitvWrVySXVSL+RUGscpyGutRnFf0T1cX7uxhCg5AStgbRynRZKZ/OMth2sc7E5ILVlRFkbN2uNWyHXuC+tikbKFohlJp+ChGXd4yeREpvAn9ZkPKm8sS0AYExm5yM7g8HBrrQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242965; c=relaxed/simple; bh=lambDYX2lwAsI5keUktYfmRvkhvX1OmYUKy53CnCprs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fuxwx10DPZWoAhpQbD/yjUZCidnLhGVqd3NZvZY2SYqM8troWJtYRU6NYr9+jkb6ahEXWz7zq9NFDpCPO7CMTtuOv+j0G9MeaC7KF8uF4YfB0sZKvm4+SxcY2Jlv16fLD7BqPma3SDGJSpJsp0YI2b+iidJuORRX86VPATEJ1S0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HUivE7Es; arc=none smtp.client-ip=74.125.225.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HUivE7Es" Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49b912e64ccso6494825e9.0 for ; Sat, 12 Sep 2026 12:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789242960; x=1789847760; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NwiXawn/cOlpKopFTshA1Oy47KkInxpQCTdPgG/ctyc=; b=HUivE7Es62sxR+XLVXov6xp7S3xA7zc5sHg2aPtEm1D76vGg1cOSKxrjCSovHeU7zj Z4XWperoqM/Nf13+t4OeR96Ig/PZiaG2eMVn+b0aS7RQPAwJkd3oF2hhQCIal448eu+Q LbRCIw7BZceNKu2BD2oaddvMuIswR0fMS3mUzgdptZG/8oCVm1fUvgSLnzjGlMgs4Aws IN5tIEcKDkmdm2wkY02rHkEkzo7Fkxw4i+mTh/TKaEIKoEUQFgEpw+6G5930rkhshcrp jjDGbby1UGLM/3SL5Loma2LMNtsSftBmNfAbsju/FlhLg7AT08XO9A5ce0zRqZD3F5FB X6PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789242960; x=1789847760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=NwiXawn/cOlpKopFTshA1Oy47KkInxpQCTdPgG/ctyc=; b=jMgx4XdkOUUr4U3vUk3L8wr2wXhW1+K0ECAVb6tTXGYjPwE1GlrAqGOBnYLCvD2XsJ sf4lnJRzc/4O+ptZifcz/nb/dZ2211uFm5r6rh/z/lQ43bJlSazA3W3BPKJII0VjP9qS FFdNy8+mEo29ysqkE+eC4nD0+fCA9epHAXuM3YsaqxBT1avMVoY1GGzWs9sN5YfShTwQ UmUevKwzcavMW/AgF8NR4x1JU8k+79GxzgAx8w7U7B1oU5a9aShcP+G8vqmFRpCnlBwc QRYJ8xSy0a2YqlYIuWYbmOcXncCIG+OV8Mr7oaMzc/LsG33K/0nCccduNX0OwdYBNlUm S+uw== X-Forwarded-Encrypted: i=1; AKwUvBwpWsZlnVk6uB3k53cOYf5P0H67l/Tqf23oUHq1E8/lw6FV2MmmvcZTPGJqdMFNspb/1F8Vi2bTVwyoUDc=@vger.kernel.org X-Gm-Message-State: AFuF++l08Y+p5o1FcUG9R1GpIdSc5a/qpr82/oJPgLQ/736FRcpq/E93 YFSorJvv8NuVsKN0XC2N6Iz3KKRuT704Sc0hd/SF2g+/UvTLRbILyE5s X-Gm-Gg: AYBFou2hDz9TdYzDUlAMTQI6kOvU77g0sotwpYV0XOCS4Fd3Ebxqq4icISpiNQuUc5T 3D6o24Gr+zHiBb7lU5sUKx3NuOZDqdFDu5Hak4Hy681CO+Mv+nRKS2UQGLSZt+IKBUf5c5lodIF 7469S4nsf9M/FaWAlIw+rb1GDZT/WxaLv3FvE1If/ZCmUKL8l2eiFxacfPv7OgAQ7PPKxxhdn6G /MsIrKJuHV5HM1CU2nWB3EKr1T/kfeFJL6+HnKa2sWIdEyRf6GNYv9UxvdgM1az6ZQOOK9CpzOg /BfML2BBHDIr/UGcSRQqM2FP+ciAjTnXOnP5+PeyCA0jjUGWTc9h9eQnC8lfg2m+Z3ojT619SWt TSzWUbQbduSAHR6IfRSmba9etR58GyclipkGv/1OrZEen2Luat3IfSggThdhpoFDtxElRXdTztj V3YRNN8aQXVLKW931zbwicPE2SWlnT/jkTRLhwFgDZbFXmUmLRfOsgM5unT9iIZGxK8qyuc3jGZ H28aLD/zLLtTK/YzVT4IZ4lIHAqzYCAs5AKy9NFjVFAiIe17tGIA2BHLino1JybkoN+zHWd54xt AzF3mleSapQ+xZ0UXb6jtq/pdep3MeeYTNZfh5WFMvDHeCbP7FdCDpsL6AWPIDfFVOcM2IEHANT 2rLp/CWI= X-Received: by 2002:a05:600c:8b38:b0:49d:272d:74b4 with SMTP id 5b1f17b1804b1-49e619a1e56mr222951175e9.2.1789242959747; Sat, 12 Sep 2026 12:55:59 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a02-3100-b260-f201-9983-e8c4-aff5-7a36.310.pool.telefonica.de. [2a02:3100:b260:f201:9983:e8c4:aff5:7a36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e60adaee4sm267089045e9.14.2026.09.12.12.55.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 12 Sep 2026 12:55:59 -0700 (PDT) From: Karl Mehltretter To: Russell King , Dmitry Baryshkov , Sudeep Holla Cc: Karl Mehltretter , Pierre Gondois , Linus Walleij , Radu Rendec , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-arm-kernel@lists.infradead.org, linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 1/4] ARM: cacheinfo: avoid out-of-bounds write in populate_cache_leaves() Date: Sat, 12 Sep 2026 21:55:49 +0200 Message-Id: <20260912195552.76673-2-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260912195552.76673-1-kmehltretter@gmail.com> References: <20260912195552.76673-1-kmehltretter@gmail.com> 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 Content-Type: text/plain; charset="utf-8" populate_cache_leaves() advances its bounds-checking index once per cache level, but split instruction/data caches consume two entries. CLIDR-based allocation supplies enough entries. Early allocation from the device tree can supply fewer and expose an out-of-bounds write. Count each written leaf and stop before a split level that does not fit. This prepares ARM for DT-based early allocation and matches commit 875d742cf532 ("arm64: cacheinfo: Avoid out-of-bounds write to cacheinfo array"). Fixes: a9ff94477836 ("ARM: 9433/2: implement cacheinfo support") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Karl Mehltretter Tested-by: Sebastian Andrzej Siewior --- The overrun was reproduced with KASAN on QEMU virt, cortex-a15, using a device tree whose cpu nodes carry only d-cache-size, so one leaf. With patch 4 alone the boot reports a slab-out-of-bounds write in populate_cache_leaves(). With this patch the boot is clean. arch/arm/kernel/cacheinfo.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/arm/kernel/cacheinfo.c b/arch/arm/kernel/cacheinfo.c index e1469b641780..860eeb03cfe5 100644 --- a/arch/arm/kernel/cacheinfo.c +++ b/arch/arm/kernel/cacheinfo.c @@ -151,7 +151,7 @@ int populate_cache_leaves(unsigned int cpu) unsigned int level, idx; enum cache_type type; struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); - struct cacheinfo *this_leaf =3D this_cpu_ci->info_list; + struct cacheinfo *infos =3D this_cpu_ci->info_list; unsigned int arch =3D cpu_architecture(); =20 /* CLIDR is not present before ARMv7/v7m */ @@ -159,13 +159,15 @@ int populate_cache_leaves(unsigned int cpu) return -EOPNOTSUPP; =20 for (idx =3D 0, level =3D 1; level <=3D this_cpu_ci->num_levels && - idx < this_cpu_ci->num_leaves; idx++, level++) { + idx < this_cpu_ci->num_leaves; level++) { type =3D get_cache_type(level); if (type =3D=3D CACHE_TYPE_SEPARATE) { - ci_leaf_init(this_leaf++, CACHE_TYPE_DATA, level); - ci_leaf_init(this_leaf++, CACHE_TYPE_INST, level); + if (idx + 1 >=3D this_cpu_ci->num_leaves) + break; + ci_leaf_init(&infos[idx++], CACHE_TYPE_DATA, level); + ci_leaf_init(&infos[idx++], CACHE_TYPE_INST, level); } else { - ci_leaf_init(this_leaf++, type, level); + ci_leaf_init(&infos[idx++], type, level); } } =20 --=20 2.53.0 From nobody Fri Sep 25 12:38:03 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 41986391E72 for ; Sat, 12 Sep 2026 19:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242968; cv=none; b=uN+H/qWk79CmBryaWl3N0BgiEalzG5OKe+EAlfrUrNe2DD+2DxXoTkLdhqkOoV3aUVijJQomLVydEjYdwI1Y3TfyCv+pIUiNHi5ACkEGW39aqcCZRTIDT2fYlh3x9Shvk5INtL7GZzzWvYVIbCzcq/xOhZ5L3xxhbctkvuaj+dQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242968; c=relaxed/simple; bh=R7KzqYlc77nKhM8iwHaTEz7kvU3XedYSYPxeFsqKjG8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DZMuoNndu+J8WHEZIh3qhxDfaPoQM/ox5OEFSCqgHlRiuyY2JTnoeMtzwFxco4czArUTFEqOjRC5CDYvTaG11jPYKW9fGluq5Shhe2bfUkaQNQ8effkmZ7J60Zcl15VFSAqfKi6Fw8cJ7cDNCGno2Fs538MZ7qPQUu2cMT0IYl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LYZ1HeFn; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LYZ1HeFn" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-49e6e69d528so6344815e9.2 for ; Sat, 12 Sep 2026 12:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789242961; x=1789847761; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8GysJsE8mePqJNLXM00GRKUzojaP5JqBAXeEHJ7TcA4=; b=LYZ1HeFnQQbHEJmYgIoQL6I6Ij8AtBqqUmDy5Lzegm7AlriG6HY7BXTmlA0+rscQau diy7iBQcPviLQcyF4nF8pl0a0tBgwwMNlJgiDYaWseto31jdA3LIqUYAvn+QzgNlZNFp acGBSWg8Vl5bZkC8DYDUNZCIfrvbuCYDbMmpVA2xpuADYW8G9pbLp+IJtzYevmm/MAW8 ns2WWumWOAH2jI+CfvXIz1hoYDatSmUCNElDQAK81cbYg+QbOZwW6T/nNxj0v08fYWvV 723zPql4/XZfmXXdM6jjU+X19pVTpmUsD9dIhnP3W4a+NQfdFyAip5/4VTdChX+BtPru xLPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789242961; x=1789847761; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8GysJsE8mePqJNLXM00GRKUzojaP5JqBAXeEHJ7TcA4=; b=PEyP/V4ofZqI3shq4kfZQavNuQaWOoT8qTK8qQUqEriQhyzIBUD1sIPbn4l+Od79Hu 07ldiE6aldZW2KkpLO+m9idYEmDrsw84Lw+JglPlDyfxItubyqYGusqFH7XoGhXOb1Bn +OMAILTiNAE5N2ZB7oKs90nz57xeYq0oOaj6ddb6MSoSSshuN1n8u4+fjL/dzq4TnxMO 1WLPkdzibpxvWXWlF9CxWNvcAqk2ipgI8zavxY66Yp5UwihfUMCcYQoNcD4jIQTqC9IR s7bKrNJ+907t4lQLQqwb+63XzHeT4rVovtyZjr7Fw0PlCqg8oA7Upco7qN1xoeG/TBF4 kvMw== X-Forwarded-Encrypted: i=1; AKwUvBxazuBydhXAdsJnmHq0QpaHeejPaHzG8tPze8dYxAdp5O5TGRPTfLeGES6mwOY82vP6RLuP+ejMuTj/9yw=@vger.kernel.org X-Gm-Message-State: AFuF++nMrZfySfsXv2yebVa9ZS202sYDCJGRHLPmLWtq27QZoiainq8V XTkRz7rdD1X8bOjwxbl2KqveFO23bxmLFVSLBHEQtd11mrR6uv58NbW5 X-Gm-Gg: AYBFou35vuxFXPJVZASYeUQ0HbldkaPaNJhcVZ1Kx8CWGF6CH7mTCaslGAkMNAc9fBw InBEN9o0vXctrabMRQcNpN6BzLpDnuhQ5qnKPXWja4Z67ExOLyXQ/PnWFtYq/WJwqjSQX+Q3LFk XyOQtt8TTYsUt5zYkudQLyt/T8BJRXOZzgfFTMzbRHJzEgHFIyHxeuhGLNY2A2KTXvdCKihdjJj qFbGpSbz9WGxu/K8Kj/1vbOJKG6NUTiUVc5VhLEpS8PCQrgddMzOXXP7Ewim8A3v+2rdjHtnym7 zhzXS5kFH+WwBaZlg0WxJHJfwlQBmmD9vfItm93PPDTwC2gHac4T8o1G7v240aO+yd5zwydf1xF hZWmz8cFW0ekykM8M5NHk6rUeh25ZRkjWs6tjprKAug/vcMkgycAT7vFkrdk7/tpyG5vwfBgztZ D/etxht9+eirCkO1Td06Agh23w1ny3KpP9LsG96PsRFX4124fdpuXOHxNrPhj93EEYnBGZkqpxm 4/zidxgPHRRBfSAUber+7dA8Dq0ZhBqLEW0ipK6aIdxyDkRco6zahi/LHe0LwTscgO6HYB4dxA+ ShiZPV6FUxG6jiZM4zAzTAnLPyAm7oImT2qVbD5Wz2RnoXvwCKycIraz3e8izH7WD8XOd+cxA6i NOnLu67g= X-Received: by 2002:a05:600c:3b18:b0:499:8704:242c with SMTP id 5b1f17b1804b1-49e61646becmr99559535e9.0.1789242960978; Sat, 12 Sep 2026 12:56:00 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a02-3100-b260-f201-9983-e8c4-aff5-7a36.310.pool.telefonica.de. [2a02:3100:b260:f201:9983:e8c4:aff5:7a36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e60adaee4sm267089045e9.14.2026.09.12.12.55.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 12 Sep 2026 12:56:00 -0700 (PDT) From: Karl Mehltretter To: Russell King , Dmitry Baryshkov , Sudeep Holla Cc: Karl Mehltretter , Pierre Gondois , Linus Walleij , Radu Rendec , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-arm-kernel@lists.infradead.org, linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/4] ARM: cacheinfo: count external caches in early_cache_level() Date: Sat, 12 Sep 2026 21:55:50 +0200 Message-Id: <20260912195552.76673-3-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260912195552.76673-1-kmehltretter@gmail.com> References: <20260912195552.76673-1-kmehltretter@gmail.com> 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 Content-Type: text/plain; charset="utf-8" early_cache_level() counts only caches described by CLIDR. An external PL310 is absent from CLIDR, and its arm,pl310-cache compatible is not accepted by init_of_cache_level(), so early allocation falls back to an incomplete count. init_cache_level() later adds the DT-described L2, forcing reallocation on the secondary CPU with interrupts disabled. This defeats early allocation on PREEMPT_RT. Use init_cache_level() for early sizing too, so the initial allocation includes external caches described by the device tree. Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Karl Mehltretter Tested-by: Sebastian Andrzej Siewior --- Without this patch, patch 4 keeps the warning on QEMU vexpress-a9 (4 Cortex-A9, PL310): the early size is 2 leaves, init_cache_level() wants 3, and init_level_allocate_ci() reallocates on the secondary CPU. With it the warning is gone and the cache sysfs tree is unchanged (L1 data, L1 instruction, L2 unified shared by all CPUs). arch/arm/kernel/cacheinfo.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/arm/kernel/cacheinfo.c b/arch/arm/kernel/cacheinfo.c index 860eeb03cfe5..31591c947254 100644 --- a/arch/arm/kernel/cacheinfo.c +++ b/arch/arm/kernel/cacheinfo.c @@ -111,13 +111,6 @@ static int detect_cache_level(unsigned int *level_p, u= nsigned int *leaves_p) return 0; } =20 -int early_cache_level(unsigned int cpu) -{ - struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); - - return detect_cache_level(&this_cpu_ci->num_levels, &this_cpu_ci->num_lea= ves); -} - int init_cache_level(unsigned int cpu) { unsigned int level, leaves; @@ -146,6 +139,11 @@ int init_cache_level(unsigned int cpu) return 0; } =20 +int early_cache_level(unsigned int cpu) +{ + return init_cache_level(cpu); +} + int populate_cache_leaves(unsigned int cpu) { unsigned int level, idx; --=20 2.53.0 From nobody Fri Sep 25 12:38:03 2026 Received: from mail-wm2-f12.google.com (mail-wm2-f12.google.com [74.125.225.140]) (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 670EF382368 for ; Sat, 12 Sep 2026 19:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242970; cv=none; b=oVAfiKe+7RPG2wNU9wBh58MDaKPwDGkZepUYt35/4gH2DBLn91uCKYSvL8KGB+4Zt7qbriM/H3NigNTb5Y42rKqfhHppwg0FiCMPTCcs+UUvPoOcI1Wux6bEOjJbndszwaqZbw5Ac50/ng2cCS00rsTwTadxs0M6fx87UXxkk28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242970; c=relaxed/simple; bh=BdaqS2x93aAnR7qyDRmryncl463GVVC0Ab+SSxVjyQw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TorEZPPvN+KrRVY4YKAHek7KQCP1sOObMuAPxqgwwlQ17VgNEmPiCiXbacTSyyxEvNvnDXgxTNeNuCbSYvMKLSmbezgztcZ3T11QBiaLZQMIxMs6FH6lXKHzOdkcEIY3rWGWX65TGdyi9f+No2Jy0nPhcwKGxHqg4vlm0XEHpao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JKZzlIWF; arc=none smtp.client-ip=74.125.225.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JKZzlIWF" Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49b94fce6e8so6607475e9.2 for ; Sat, 12 Sep 2026 12:56:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789242962; x=1789847762; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Iv5Y9hzbKwVTvwjYbkj7A4OWiAYcXcebXQ5vuapgDoU=; b=JKZzlIWF2Hhf7sHDs2OR+/W3Ob/eqWuuK205rP1cjCOb0YkrqFkY3FKvPYcAf+KbDX BKiEGcWcBccnp8UPZHahTIYC/A2b9sU9nvxqS61chU+Z2WM04kSefu87edIP6Ndg2uNp JPA0fozdZ1w6uk/0qTfu4SqiMhYapvdc7P6su185RngKDBwCy/uwRFIewFKu8FUf736q DrvdKprxOlUVcG/XT9GuC5MojX8uQdLXpem1kuOoXca5SQM34gGvalICdFwTrhxrN0Sh LjsshcZGDhOtmrLV1egiFQHg1jfJ+hH3qJxJ5RNhFLw8xKeAF9yNr6utfxoJSU+Ve5p1 I8qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789242962; x=1789847762; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Iv5Y9hzbKwVTvwjYbkj7A4OWiAYcXcebXQ5vuapgDoU=; b=Igmo4Ja4c7bL5bzzO/PNZg0JEzA+77dU1TFus3C1Y2uGBYUvoytqjsxKqMlCH/cTkS W0UitPdobyCcFOcBaNlw6WH4dJpJXD+Y9N1/BQvHIkpjTjfkv/AHgyHDgnz8hBs/xSlw CwcFG3fYEMI+Vi5zCywYMr+p8fHc1tbsX/VloqIuqZJLk/3gkz9AuyT3TW1BtlottzzO fdC8xKfFZA6z6p8CF80CXbB0HLIecCzhzgn98LuVX3BYqIpfP6ml0D2sbhuVBGq7ZMfm 6cRPh+PYQsLBJL7a9ZkRzsysqOJ5LTsk+CsuJFgvXMvgBtHmekuExS4LiWMC0pPsp7bd koIA== X-Forwarded-Encrypted: i=1; AKwUvBwsV/s41KzfJQigmbQQOvn+mrgfPpfuKnGoytjwdOPRSgOiX54wguUEvK1vrWBv1HVfCQGpBnjZ39ednK4=@vger.kernel.org X-Gm-Message-State: AFuF++mXTX6iQna1bTI/MN82Rysnccv0WAg65joswACviuzs1k9RY5R6 WE+bHl/om/rUEHt/eym4lCQ3SDwtCeCu5HS+7dvcS4n8YEo6ZmlqIujE X-Gm-Gg: AYBFou3J8prCexIr0RmDE5oAvL8DNnX39uu3AmB7XMDZrQcZL8n7A0tf5/tkwljkoSq nZhvYFWRnVLS7esFobst+tfEJjc9Wcd5O9eNPVnJ7SkCy2hLuqwQKoFNcx4RrNP9KBDULrFoDQy 0PqVapycdfdQ+kbtmz4MIgiMgL2JOC/eEcHpUnizhTZ1FpxmNaCN8YxYdVFxFIc/6LgoU9Ue8u5 PFjc9wegcll5128Tb06Wt19IWXDEwQnv9PWaLlsZeH7ifH0G4K3wMqy8PvWVVj0LEWNi4aWY89g 12IoIoeRfYLVHUy9gOqRGiKw/M+w/TGoq4oEX71q0sGQ9L2kiqGzHPGSLvwnRuzozSKWiLYVUGr R2f5IN1ZzaET5MxzRxNW2KNgBzhFJMF0nHD/IXL2zHAmIgH0L4NHTwf5Q/y/PCGl7Wk7wOGGpQ8 8qbW8B3jYHHZpmI2a1TX40dLtSUjSCu2v208R36m0GHwAWKjMk3g51Xea6Q9OrdOxcb1WrT8KBC uLzrTsBYEKv0TYMSLPpoI7Ati0kbVl4t6bkBj4ulmExEARMm2wEJZrLwTy+hTG4oJU7hdRL9LmQ mgsD4udPAp9FQXj+1WtsFNWbEutP3pb9npG1mxs0oX/pBXPvYwzbo6ENSkd5nSzVtIQyY6VVw0d HSEqBYYY= X-Received: by 2002:a05:600d:4452:20b0:499:b65d:124f with SMTP id 5b1f17b1804b1-49e6198c2aemr79301175e9.11.1789242962176; Sat, 12 Sep 2026 12:56:02 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a02-3100-b260-f201-9983-e8c4-aff5-7a36.310.pool.telefonica.de. [2a02:3100:b260:f201:9983:e8c4:aff5:7a36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e60adaee4sm267089045e9.14.2026.09.12.12.56.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 12 Sep 2026 12:56:01 -0700 (PDT) From: Karl Mehltretter To: Russell King , Dmitry Baryshkov , Sudeep Holla Cc: Karl Mehltretter , Pierre Gondois , Linus Walleij , Radu Rendec , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-arm-kernel@lists.infradead.org, linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 3/4] ARM: cacheinfo: guard the CLIDR read in populate_cache_leaves() Date: Sat, 12 Sep 2026 21:55:51 +0200 Message-Id: <20260912195552.76673-4-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260912195552.76673-1-kmehltretter@gmail.com> References: <20260912195552.76673-1-kmehltretter@gmail.com> 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 Content-Type: text/plain; charset="utf-8" ARM1176 and ARM11 MPCore can be reported as ARMv7 by cpu_architecture() even though they lack CLIDR. populate_cache_leaves() therefore needs the CTR-format check used by detect_cache_level(). DT-based early allocation bypasses init_cache_level(), so its check no longer protects populate_cache_leaves(). A combined ARMv6/ARMv7 SMP kernel can reach this path on BCM2835, whose DT describes its caches. Share the CLIDR capability check between detection and population. Return -ENOENT from population when CLIDR is unavailable, preserving the existing absence of cacheinfo and avoiding a new topology warning. Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Karl Mehltretter Tested-by: Sebastian Andrzej Siewior --- Reproduced on QEMU realview-eb-mpcore (ARM11 MPCore, reported as ARMv7 by cpu_architecture()) with a device tree carrying i-cache-size and d-cache-size on the cpu nodes like bcm2835.dtsi: with patch 4 and without this patch populate_cache_leaves() reads CLIDR, which QEMU returns as zero, so every leaf becomes CACHE_TYPE_NOCACHE. Real ARM11 does not implement the register. With this patch the read is skipped, the boot is silent and cacheinfo stays absent as before the series. arch/arm/kernel/cacheinfo.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/arm/kernel/cacheinfo.c b/arch/arm/kernel/cacheinfo.c index 31591c947254..993c8a134786 100644 --- a/arch/arm/kernel/cacheinfo.c +++ b/arch/arm/kernel/cacheinfo.c @@ -80,19 +80,21 @@ static void ci_leaf_init(struct cacheinfo *this_leaf, this_leaf->type =3D type; } =20 -static int detect_cache_level(unsigned int *level_p, unsigned int *leaves_= p) +static bool clidr_present(void) { - unsigned int ctype, level, leaves; - u32 ctr, format; - /* CLIDR is not present before ARMv7/v7m */ if (cpu_architecture() < CPU_ARCH_ARMv7) - return -EOPNOTSUPP; + return false; =20 /* Don't try reading CLIDR if CTR declares old format */ - ctr =3D read_cpuid_cachetype(); - format =3D FIELD_GET(CTR_FORMAT_MASK, ctr); - if (format !=3D CTR_FORMAT_ARMV7) + return FIELD_GET(CTR_FORMAT_MASK, read_cpuid_cachetype()) =3D=3D CTR_FORM= AT_ARMV7; +} + +static int detect_cache_level(unsigned int *level_p, unsigned int *leaves_= p) +{ + unsigned int ctype, level, leaves; + + if (!clidr_present()) return -EOPNOTSUPP; =20 for (level =3D 1, leaves =3D 0; level <=3D MAX_CACHE_LEVEL; level++) { @@ -150,11 +152,10 @@ int populate_cache_leaves(unsigned int cpu) enum cache_type type; struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *infos =3D this_cpu_ci->info_list; - unsigned int arch =3D cpu_architecture(); =20 - /* CLIDR is not present before ARMv7/v7m */ - if (arch < CPU_ARCH_ARMv7) - return -EOPNOTSUPP; + /* The device tree can describe caches CLIDR cannot fill in. */ + if (!clidr_present()) + return -ENOENT; =20 for (idx =3D 0, level =3D 1; level <=3D this_cpu_ci->num_levels && idx < this_cpu_ci->num_leaves; level++) { --=20 2.53.0 From nobody Fri Sep 25 12:38:03 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 3B337392814 for ; Sat, 12 Sep 2026 19:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242971; cv=none; b=m9qw8RQz7BnPwfs8xmMsomDK3WDCIOIA1KxP+2RcTISpIqjv6HGzzWXTG/US2Fkxe3XCj+XfFGZcSfNHJiMjZE7k7mjXNAQo0YlGRDR/BSawrYYVVzJ4z7xkGUpUVoFZHdOlx/ipO9bSdbOf2Y71yf0tznaotW1uUe7j7ZG8AbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242971; c=relaxed/simple; bh=rN3M/EIKOAXQYOqvo5H5srYi0ltpPT+F1jN5KbTizKk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p+C66EmozTns8f1r3PP3fczJ5kMUL79zG/ZP5NyXeF8hB3UhCwVnFciepsSTzwOMxOa5co7/B+NM6M/1A1h2HdgohaoktzUYgJwDDSy1WozCXrG4z5ZehQOAdRXXahr9NrgQrnXIvh1HuVaLlW4TG/C11AlyE0Cxz/xFLiFIq14= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d4uTv9Sp; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d4uTv9Sp" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-49d0da752ffso25223735e9.3 for ; Sat, 12 Sep 2026 12:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789242964; x=1789847764; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SudqM4dinshG/ga4dKzazwfwaSNRtgAeUisYk5patHw=; b=d4uTv9Sp2tahE1qfecaY3kM4f9nFZ4PrLqJzaE8mcfB+JzeiSTzvdAQLCN13FlMveZ 6v9RAP6etEWzjbawTU8m9/B6K62h16+UMAX0yru1ElZtQGfkJLOhgV5RgpNWxi3HilZD dq/tcZGRrcMT0SMw2piauini08RSexDolEP6JEWztAZw7adsYhjQ+plohSl1uminPd5H FKwAHljBEz65apY5n+Oaj8iFmDxosrYjeRUYbg1wgu3LvGUTcqBT9Pf8RrLMXKZb53y2 HvnO+wadvhdXMruHEWrrVuxPVvGrEHv4OZeQ9ncfpzyjtJOzl7Wb1jdah8eJ2AtVZMHw JovA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789242964; x=1789847764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SudqM4dinshG/ga4dKzazwfwaSNRtgAeUisYk5patHw=; b=IBescRBOntCermHFPlf6As1vgLEzuPNP9JtzW17Sivm/ALPiiuOCvWmUNykSCGf4mg WeWy0mx0O7qAcJpFVEXLXHPb4gTKPsmzJ0Ba6DbNIbOvef7GqtdMWf7HPGfRt+ebYAfs u+98HN/GXdWqbRXBwMzo/muBQW9wyE71BnMCItLI0kdqrNLavWWvyjRLjOXP46NOxwRg 2c7U7+yewMWyTeYt2w62yP5yyWnJDLyAxDSjmNZG1zHpsUIiccCE5CJWzGWrK1Gcc+wI NHNTGD4JuH6io55xFsTxgCk9ngMnXKkyTSoAonrM7Tf1GS+yuXgvnNPmfraIOELfOzaz 0SIg== X-Forwarded-Encrypted: i=1; AKwUvBxlJGN3EvjgjNIrodAfFklw2RSRsLE+YdB2NwxnvZv4ah9ssbzKTd5Go8bKALyAH0ou4zfKQ+oqY3hjeGQ=@vger.kernel.org X-Gm-Message-State: AFuF++l99zrndguYtPaSRkhVG/5AIlfH2lR/gAmvOS/gLbvwN7RcKV+f xw2Cg/i8aiME9hTuaanrQ5zx7IEsHGp3eC9nFEP+7RT/iTDTtbmDppGW X-Gm-Gg: AYBFou273V0dtUfQOCEDuhKObHlEzqEMlFmqMccwEzBI2SttIc1vq7gJkPjyA6QStW/ Z4BMNKOi8KFgtkC1HINYl2XguFA3Jxajfb7wEuzovjl105NtCWtjVuHGrjWimBTC2ee4o3RVqCQ yiMenUeDuU3dpg5xHR8s7VsNOI7hdJOC42WSapAmHYXjLIJ9X7aaqlUhp4x8ZBKv4cyuULy/OJ7 rwyzvNji8No02UcdZzzrW//ySwk3r87tYVEI4juih689jdy8YlOvUfnZn7fTEDLp4OIWU83BYkA ALTQhGuc/FxWZdF/1NnKYsDSr5dWgzuFrhiKbF7yEK60suHKTfQByjXv+wRaPAJOB+h1P/HKQ0u ZBsQRn9w90OQCTrLSdr7oTSDJUjsjo6RnfMd5+wiZWkWPQ2tPZktURPZfN/95/b3G3T6p8bqVve a+yQJbOjyMBLjfBXZLQZ9jRtckRDIa9/crx9pABCLHyQpaaEbvUUIM1b7bnulURrFvnqSoQoGzW olTLq5LlyJmt5InTTv2hp49h+Vly5YSkDMXDPnINNcov4bpQQRwC8i0BvHOydWgyZDIAT8pMj8d T+mu/XOmc7HZYrbfC5ui0WI39anS59X7yBZF28FHTWwgVEJ/s6u4IhnL/a4c1x3DP32kxUzIqsU 1p+0Fjev1 X-Received: by 2002:a05:600c:3115:b0:495:4d88:e630 with SMTP id 5b1f17b1804b1-49e61989e79mr109783245e9.10.1789242963500; Sat, 12 Sep 2026 12:56:03 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a02-3100-b260-f201-9983-e8c4-aff5-7a36.310.pool.telefonica.de. [2a02:3100:b260:f201:9983:e8c4:aff5:7a36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e60adaee4sm267089045e9.14.2026.09.12.12.56.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 12 Sep 2026 12:56:02 -0700 (PDT) From: Karl Mehltretter To: Russell King , Dmitry Baryshkov , Sudeep Holla Cc: Karl Mehltretter , Pierre Gondois , Linus Walleij , Radu Rendec , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-arm-kernel@lists.infradead.org, linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 4/4] ARM: topology: allocate the cacheinfo early on the boot CPU Date: Sat, 12 Sep 2026 21:55:52 +0200 Message-Id: <20260912195552.76673-5-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260912195552.76673-1-kmehltretter@gmail.com> References: <20260912195552.76673-1-kmehltretter@gmail.com> 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 Content-Type: text/plain; charset="utf-8" ARM secondary CPUs allocate cacheinfo in detect_cache_attributes(), called from secondary_start_kernel() with interrupts disabled. With PREEMPT_RT, the allocation takes a sleeping lock and triggers "BUG: sleeping function called from invalid context". Call fetch_cache_info() for each possible CPU from init_cpu_topology() on the boot CPU, following commit 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU"). This supplies the arrays before secondary CPUs populate them. Suppress -ENOENT and -EOPNOTSUPP, which leave cache detection to the existing late path. The CLIDR fallback uses the boot CPU's cache geometry. A secondary CPU with more cache leaves can still require late reallocation and trigger the warning. Fixes: a9ff94477836 ("ARM: 9433/2: implement cacheinfo support") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Karl Mehltretter Tested-by: Sebastian Andrzej Siewior --- Full warning on QEMU virt, cortex-a15, 7.3-rc2, PREEMPT_RT: BUG: sleeping function called from invalid context at kernel/locking/spin= lock_rt.c:48 in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: swapper= /1 Call trace: rt_spin_lock from ___slab_alloc+0x68/0x728 ... __kmalloc_noprof from detect_cache_attributes+0xe4/0x734 detect_cache_attributes from update_siblings_masks+0x10/0x174 update_siblings_masks from secondary_start_kernel+0xec/0x120 PREEMPT_RT became selectable on ARM in 7.1 with commit c6e61c06d606 ("ARM: 9463/1: Allow to enable RT"). The PREEMPT_RT patch queues carry that change for 6.18 and later, so 6.18.y is affected as well. QEMU virt, cortex-a15, PREEMPT_RT, 2 and 4 CPUs: the warning is gone, the cacheinfo sysfs tree is identical before and after, CPU 1 survives an offline/online cycle. Same on a non-RT build. QEMU realview-eb-mpcore, ARM11 MPCore, 4 CPUs, ARMv6 plus ARMv7 SMP kernel with PREEMPT_RT: fetch_cache_info() returns -EOPNOTSUPP through the CTR format check, no message, no cacheinfo before or after, CPU hotplug works, kernel messages otherwise identical. Raspberry Pi 400, four Cortex-A72 CPUs, 32-bit PREEMPT_RT 7.2.6-rc1, full series: the boot warning is absent and all 12 cache sysfs entries match the unpatched baseline and earlier topology-only run. The live DT describes the shared L2, exercising DT-based early allocation. CPU hotplug is unavailable on this platform. arch/arm/kernel/topology.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c index 2336ee2aa44a..e6b50cd43ce5 100644 --- a/arch/arm/kernel/topology.c +++ b/arch/arm/kernel/topology.c @@ -12,6 +12,7 @@ */ =20 #include +#include #include #include #include @@ -238,8 +239,20 @@ void store_cpu_topology(unsigned int cpuid) */ void __init init_cpu_topology(void) { + int cpu, ret; + reset_cpu_topology(); smp_wmb(); =20 parse_dt_topology(); + + for_each_possible_cpu(cpu) { + ret =3D fetch_cache_info(cpu); + if (!ret) + continue; + /* CPUs without a usable CLIDR return -EOPNOTSUPP. */ + if (ret !=3D -ENOENT && ret !=3D -EOPNOTSUPP) + pr_err("Early cacheinfo failed, ret =3D %d\n", ret); + return; + } } --=20 2.53.0