From nobody Sat Jul 25 06:09:17 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 307703C73EC for ; Thu, 16 Jul 2026 21:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784238168; cv=none; b=Fb7wP56znEonNutBVGCodWfew9tgPUUInrD1QU5T/KvADMsRmljZMB6gMim42IbDov9qYUkwgOPA5BqR7rQeXzz5hrLVi1HxXVKzj5GsqefOgzUzlK/MWKG24Wr/Aj6FcLRAOjRYw5wf+iKUyZpQFRU0AAGplQhh3n3ql4Al9BY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784238168; c=relaxed/simple; bh=zjLFdBciCH36gQX93iOqveGy1R/ywZ1tsnZtfSHwo/k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gAxT4J1G7B6e0NltQ4uZ/FlGq+piynrt3OL4+nynFbgiwMbIRG8TrabXa1ywfy4Aj7Q1u+9axDdUNqlZ4bSFoOYSzHVYn0RlfT2HvEZoSm+1ekPVVWzIMJv43G0LZp9Q5N7y5HUpbhUEYCy6vdXDnG+VqtDEIa3N4xeLeIAkMtQ= 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=kW3bo/Ol; arc=none smtp.client-ip=209.85.128.46 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="kW3bo/Ol" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-493f4638f4aso32042865e9.3 for ; Thu, 16 Jul 2026 14:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784238164; x=1784842964; 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=eyGPsVw0MJSV96XCp7cxneDUGR8CvSyWL+Po087qX1c=; b=kW3bo/OljgOV+R69sQpY6qN0cfYx6tMUBnIV8jazf1Lk3a8431MKw8yP7Cn31FENbj Gslg/K9Hp55oYb3VXoCbXAhX71CPey6UKiyDC+A17n99IRx85E2qzM9KoxEp+DFqTDDI xjgs0U2LhFDYKPNms1Mr6it7aw9BNP7S77SWSh/2q73vLtqTmwcnWmNneorsQGuz+7jI GncuTSmI/YcRvG1t/4U0ENAJv82qs9zF+ZzZhTtH334TgIav90CP7FDlk8VH66HBs8Y5 eYsL/0Kiskuq1wz5k1T+hbf9IC89p6fP2hZJXxyIbyo/DetcBXobcSMC/L1P7WAn0iNn TNUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784238164; x=1784842964; 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=eyGPsVw0MJSV96XCp7cxneDUGR8CvSyWL+Po087qX1c=; b=N3Ofd82gxUaAH1goV41uvdBX+Tk31dtyj/CE2k31KjvKm3U7nekeXYdbYnFywn+f3r Se0hhqv7KUmQp+Di84ogEcltMAEIGGsBQw3uBbV3FuFYLOanmFJnU3n/GxX8yoB0o9kT kSGq9QjazFOkzFnXZkw2rwROB8YxmOHcME3IQieGBHZPK6oaRWKdYqyYPVdYUCHNHGgO 4qlD41tn9vTktEprOevW2t5oP4k4q7ShKKyT8i/uJHg3t4pNHgRLP2TAfLermOTdcDZI 3VurBKq3ZYz32EOTcJRnflDpYllRURmeNjUvUGwkkGwIKu8x6rUEBF8qJXLaVtxPbAaa pG2g== X-Forwarded-Encrypted: i=1; AHgh+RqI/xqvTj/k605o4ET7TH3p6RxYwZDuY1uLw3TIr82skPr7k12frEj2JEYFZA/E19WiTR5rOE8Rvwa9WSg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8PkiH6/YK4G31npl5NwIDIHKeTKZ+1+lso+/gpjjsvjIglHiy LPOMVWWmIm3wswli6uRRlaSFgShzPQlvod/q6sNjwDM2lqaux4sFHb6v X-Gm-Gg: AfdE7cmIBK9etOlE1AuHwbKDnL+NQzhegmZNdQ6AZbfxHb8sYpxC0sQBHLLV962DSRP 1BG/YPbeMgDmL8xmeUbE619CkcVb96YAX+UB6/gzP4iWDLl3BMzJBYk79xZM/GaudVNeCD74eLV FpLeVSx2NPn1slNW6icPE4aAj1giBcQ7ROylbQI397USqwz6LZj3vS8IqvuX2kOUNtrATBx42zX tRyF9j97lewPaLn9D0V/KuYn804kttmXfbb3OhqdWa1S9ObWZ5ySe8sJ9ovaiSO90QVoO9ytRyD ksAlkMK8Y1z4KBGRDgqmauIyJx1bBIAlQerwIIu504Jz2qYC6GAGS7szRTIb5Mrbo1rPSMQL9dq wn80yTDhfNSzuzIJLWBMUsWdGpnEZIgbK7wuU6Mmgc3ekDUk5wPmzDT6DepjQwB3gopCqG3djVj izDIslgmseZaUg3JnfD7O/ovvbaLhgAixfNpzMgTm1h1txq7mfHyxbVMBVEXxskIQ= X-Received: by 2002:a05:600c:b8d:b0:493:bcef:565c with SMTP id 5b1f17b1804b1-49548391e68mr12720315e9.1.1784238164132; Thu, 16 Jul 2026 14:42:44 -0700 (PDT) Received: from localhost.localdomain ([102.184.143.235]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549a47de7sm2280035e9.7.2026.07.16.14.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2026 14:42:43 -0700 (PDT) From: Mohamed Ayman To: Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , Alexander Shishkin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , coresight@lists.linaro.org (moderated list:ARM/CORESIGHT FRAMEWORK AND DRIVERS), linux-arm-kernel@lists.infradead.org (moderated list:ARM/CORESIGHT FRAMEWORK AND DRIVERS), linux-kernel@vger.kernel.org (open list), linux-rt-devel@lists.linux.dev (open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT) Cc: Mohamed Ayman , coresight@lists.linaro.org (moderated list:ARM/CORESIGHT FRAMEWORK AND DRIVERS), linux-arm-kernel@lists.infradead.org (moderated list:ARM/CORESIGHT FRAMEWORK AND DRIVERS), linux-kernel@vger.kernel.org (open list), linux-rt-devel@lists.linux.dev (open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT) Subject: [PATCH v3] coresight: Fix scheduling while atomic in coresight_cpu_pm_notify() Date: Fri, 17 Jul 2026 00:41:54 +0300 Message-Id: <20260716214155.2049564-1-mohamedaymanworkspace@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260712210446.14290-1-mohamedaymanworkspace@gmail.com> References: <20260712210446.14290-1-mohamedaymanworkspace@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" Dropping the last reference to a coresight_device can trigger a kernel panic on PREEMPT_RT builds due to a "scheduling while atomic" violation. When the CPU enters an idle state, coresight_cpu_pm_notify() is invoked with local interrupts disabled. It calls coresight_cpu_get_active_path(), which currently uses coresight_get_percpu_source_ref() to get a kobject reference, and then immediately drops it with coresight_put_percpu_source_r= ef(). If this put_device() call drops the very last reference (e.g., due to a concurrent device unregistration), it synchronously triggers the release cascade. On PREEMPT_RT, free_percpu() takes a sleeping rt-mutex. Furthermore, any parent device in the release chain might also acquire sleeping locks, causing a system crash in the atomic PM context. Fix this by eliminating the get/put dance entirely in the PM notifier path. Since coresight_cpu_pm_notify() runs with IRQs disabled, it is safe to read the per-cpu source pointer directly under the coresight_dev_lock, check the mode, and return the path without unnecessarily manipulating the kobject refcount. Suggested-by: Sebastian Andrzej Siewior Signed-off-by: Mohamed Ayman Reviewed-by: Leo Yan Reviewed-by: Sebastian Andrzej Siewior --- drivers/hwtracing/coresight/coresight-core.c | 22 ++++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 6d65c43d5..713bcff53 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1850,25 +1850,15 @@ static void coresight_release_device_list(void) static struct coresight_path *coresight_cpu_get_active_path(enum cs_mode m= ode) { struct coresight_device *source; - bool is_active =3D false; + struct coresight_path *path =3D NULL; =20 - source =3D coresight_get_percpu_source_ref(smp_processor_id()); - if (!source) - return NULL; - - if (coresight_get_mode(source) & mode) - is_active =3D true; + guard(raw_spinlock_irqsave)(&coresight_dev_lock); =20 - coresight_put_percpu_source_ref(source); + source =3D per_cpu(csdev_source, smp_processor_id()); + if (source && (coresight_get_mode(source) & mode)) + path =3D source->path; =20 - /* - * It is expected to run in atomic context or with the CPU lock held for - * sysfs mode, so it cannot be preempted to disable the path. Here - * returns the active path pointer without concern that its state may - * change. Since the build path has taken a reference on the component, - * the path can be safely used by the caller. - */ - return is_active ? source->path : NULL; + return path; } =20 /* Return: 1 if PM is required, 0 if skip, or a negative error */ --=20 2.34.1