From nobody Fri Dec 19 20:36:27 2025 Received: from mail-oo1-f74.google.com (mail-oo1-f74.google.com [209.85.161.74]) (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 DB72D229B30 for ; Tue, 15 Apr 2025 18:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744742821; cv=none; b=OBoGZbxMgZf943wXf5EdmYD6o+2SqnQdSa880ZRAvWyiwsmp37SerfwR3YgtsVNFtWgrX8vkoAPNfE/qpAsXsuTHwFBlfjOjdupwkqFAMoKUzuBbHu52KRi8sUXhqilII0gDV70mUN2dC2EoQBMT/XAnK8C4DD4fBNi1IkGjxoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744742821; c=relaxed/simple; bh=anZkANSwSDCmjOipxerQH1QTYidJBJdyetokzdU3tbk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RsMDLocUkgGJhgN5BShvTtClEZADmZHzR1Eut/kdJpUu0EfDGIHo5eoM0q5G/azeoW80rQLxws1nUpa/GNxa3CcR/PDnvXa5/HRqV6PocPQIcX3R2Uj9hvSQOXsY5Clne3/e2pdseAwLWBTrrcr6PAFva0XRmfRPnmgn3fe7yEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hndV2SL+; arc=none smtp.client-ip=209.85.161.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hndV2SL+" Received: by mail-oo1-f74.google.com with SMTP id 006d021491bc7-601ae9681c0so4537599eaf.2 for ; Tue, 15 Apr 2025 11:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744742818; x=1745347618; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IegfUhI5gVIS8XkKPR5l9zWak8XwOvvgw8K+zjrd1EM=; b=hndV2SL+f+qcyHwm2/Eznt35jVTx0E7DfRAqxlGuE/ylUtKdYTj7GjvjvcJTJ4MsZ0 Tr3WULCfCSPK2OsiHOVKAmEr20u3BCam+AK31ql5990bdouVCBK4SCov1C/NCzac1vJC nb9JAGRTad44UsuaaAmiz3RUZqwBcqTaVl0qQb/4o8r9trqyFqrickNXqg5qoyknkIzl r1jVIHdwP5jDR5ujxQ/lLJYTEWPPrDPbkY6k1cYFZxeHQMxMPq+jKFxC5QOirjXqlcgy UZdgE6es/EbCCyH/CQRSIOFHqbtMkZmSQdfMSA0Flaih3uSensVV9d0XA0J3ryA6gY2y 5P/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744742818; x=1745347618; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IegfUhI5gVIS8XkKPR5l9zWak8XwOvvgw8K+zjrd1EM=; b=uiAjfdytuMIOLdegKaghOM0MOjguZbhsNzP0zPXxCq6a3uHxqp6+kFnriIqw0/7aML 4tfGfLOGcPTOwgmdk7Ybi+0tdTlc2pb1qo+V+pGf6KGixh4eYytqLQC1yRp8Kcw42F3c rVxpxfWSYpVjHmcLaYU1w2xfeI65vMmg8V9xgNWzm1DYtbiPD1QyZEER/drD8jFDaNyT krpw9ZzJJr0K/1O+qzZNzooUrUU8qNNxyLKBwsCvRkftaT+ZwlXZgD0Vmsw9yTrpD/Nq wuw1HRQwGox//5F6FQRhZX9PLfE1/4u1SFpnM3oB98VylSaI4k1OJQWH/PD0RHrWOLi1 GIlw== X-Forwarded-Encrypted: i=1; AJvYcCUQxd3KFj1W2fz0HbZwNYj8Wkq/m9hI4P/bQbJfApaP/iVmWG8zwn8/LOguGv3dhDxzu3dT55Pp8Vne1n4=@vger.kernel.org X-Gm-Message-State: AOJu0YyWQ/AVRBps2D8GOxlsR6O1U8XFRAkwpRZMmM5EmbjLqPexB7Xe cuY9/x3J74OxscszvZJIaribxy58NrL1ANv6JZBio5+pH7TyBeYx8dNioCRWdNG97hgy+h651DM 7 X-Google-Smtp-Source: AGHT+IEQi8PNtHVcRy7LuBEXq5xHg4BzdFcTSBuGvgAfDtsQNpuwbpRyY+zu7kia13Vkit4PH+1HBu9PL1E= X-Received: from oabqw7.prod.google.com ([2002:a05:6870:6f07:b0:2b8:e401:9c8d]) (user=yabinc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:e05:b0:2c2:343d:1368 with SMTP id 586e51a60fabf-2d4c3eaca2dmr192919fac.29.1744742817901; Tue, 15 Apr 2025 11:46:57 -0700 (PDT) Date: Tue, 15 Apr 2025 11:46:48 -0700 In-Reply-To: <20250415184649.356683-1-yabinc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250415184649.356683-1-yabinc@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250415184649.356683-2-yabinc@google.com> Subject: [PATCH v4 1/2] coresight: catu: Introduce refcount and spinlock for enabling/disabling From: Yabin Cui To: Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , Jie Gan , Alexander Shishkin Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yabin Cui Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When tracing ETM data on multiple CPUs concurrently via the perf interface, the CATU device is shared across different CPU paths. This can lead to race conditions when multiple CPUs attempt to enable or disable the CATU device simultaneously. To address these race conditions, this patch introduces the following changes: 1. The enable and disable operations for the CATU device are not reentrant. Therefore, a spinlock is added to ensure that only one CPU can enable or disable a given CATU device at any point in time. 2. A reference counter is used to manage the enable/disable state of the CATU device. The device is enabled when the first CPU requires it and is only disabled when the last CPU finishes using it. This ensures the device remains active as long as at least one CPU needs it. Signed-off-by: Yabin Cui Reviewed-by: Leo Yan --- drivers/hwtracing/coresight/coresight-catu.c | 25 +++++++++++++------- drivers/hwtracing/coresight/coresight-catu.h | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtraci= ng/coresight/coresight-catu.c index fa170c966bc3..3909b562b077 100644 --- a/drivers/hwtracing/coresight/coresight-catu.c +++ b/drivers/hwtracing/coresight/coresight-catu.c @@ -458,12 +458,17 @@ static int catu_enable_hw(struct catu_drvdata *drvdat= a, enum cs_mode cs_mode, static int catu_enable(struct coresight_device *csdev, enum cs_mode mode, void *data) { - int rc; + int rc =3D 0; struct catu_drvdata *catu_drvdata =3D csdev_to_catu_drvdata(csdev); =20 - CS_UNLOCK(catu_drvdata->base); - rc =3D catu_enable_hw(catu_drvdata, mode, data); - CS_LOCK(catu_drvdata->base); + guard(raw_spinlock_irqsave)(&catu_drvdata->spinlock); + if (csdev->refcnt =3D=3D 0) { + CS_UNLOCK(catu_drvdata->base); + rc =3D catu_enable_hw(catu_drvdata, mode, data); + CS_LOCK(catu_drvdata->base); + } + if (!rc) + csdev->refcnt++; return rc; } =20 @@ -486,12 +491,15 @@ static int catu_disable_hw(struct catu_drvdata *drvda= ta) =20 static int catu_disable(struct coresight_device *csdev, void *__unused) { - int rc; + int rc =3D 0; struct catu_drvdata *catu_drvdata =3D csdev_to_catu_drvdata(csdev); =20 - CS_UNLOCK(catu_drvdata->base); - rc =3D catu_disable_hw(catu_drvdata); - CS_LOCK(catu_drvdata->base); + guard(raw_spinlock_irqsave)(&catu_drvdata->spinlock); + if (--csdev->refcnt =3D=3D 0) { + CS_UNLOCK(catu_drvdata->base); + rc =3D catu_disable_hw(catu_drvdata); + CS_LOCK(catu_drvdata->base); + } return rc; } =20 @@ -550,6 +558,7 @@ static int __catu_probe(struct device *dev, struct reso= urce *res) dev->platform_data =3D pdata; =20 drvdata->base =3D base; + raw_spin_lock_init(&drvdata->spinlock); catu_desc.access =3D CSDEV_ACCESS_IOMEM(base); catu_desc.pdata =3D pdata; catu_desc.dev =3D dev; diff --git a/drivers/hwtracing/coresight/coresight-catu.h b/drivers/hwtraci= ng/coresight/coresight-catu.h index 141feac1c14b..755776cd19c5 100644 --- a/drivers/hwtracing/coresight/coresight-catu.h +++ b/drivers/hwtracing/coresight/coresight-catu.h @@ -65,6 +65,7 @@ struct catu_drvdata { void __iomem *base; struct coresight_device *csdev; int irq; + raw_spinlock_t spinlock; }; =20 #define CATU_REG32(name, offset) \ --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 20:36:27 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 CE6E3230BF5 for ; Tue, 15 Apr 2025 18:47:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744742824; cv=none; b=tPjxl4zVj+EvyXn2IUrxJsI7Q0t4eMliR0z+s3T0EAr+LikMKBcZ1TEGs+okhmCW/QDgWqPZMRxSRi2DDg5EQU26EjEvephM2F0wDdRCtjqnhZVdhQ6Qu7VsG1gI2QWxmOJvmQwaI8alqb9mdweEUa/LgbtClXJC79of8JEpc6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744742824; c=relaxed/simple; bh=OU+xASx9DV5Tg9l46em3oZZnzIkD12NST2/O9VLP39I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NGm+L13tXZHi4l0qTpukOibdHrjbZqPL7ih7IpyqeapcGZc6icQueFDTVowBPbwpe9EoGqxDJeOCqbj9vcyKRdyPSy8fO5zHrPoznCbAMyCaAmNazK/GhX7LWBivoVGX81U5WQSBI5zojS5NBDgVcC5YWBPmuz3Ltqpb3sFE30o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lTiVHIdm; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lTiVHIdm" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-227ed471999so51569485ad.3 for ; Tue, 15 Apr 2025 11:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744742822; x=1745347622; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vrce6Ur/Z1bBcoSkzpW7fAIgWwmrsZNhT8/LajKfaJQ=; b=lTiVHIdmBahsZHGhBXy06sl33g+L4M2OzdCAOT8CJMZQlmQ5eS7xV6e+eyzAWV+Yo5 ghI/6zXkhnA20Z0x2xPFPdxu15CiCvwx9UPaSwTMJIihG6llt7P4+p9tgYk8gBSQnEam lyZoIVfd9wLe7alsZ5YqDjBET6BVIIbOqOz9EMkOWT3RuhdJ+Lk5NDP2J6hMMENZYWGp kK22YnMQ3yDvgIsqWHI+04gu1TCO6KFIInweFGr09K8ZV4n7z1tflXmbcwyD2hc6YvVe OlP3fwAihxE1aGkk81Fd+HGYNbvhqm7tceXfk5QEacSDRFlo1d9MKvuMn7nk+Kl61S2r 37/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744742822; x=1745347622; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vrce6Ur/Z1bBcoSkzpW7fAIgWwmrsZNhT8/LajKfaJQ=; b=JzXfXT0g2bXXj+mU5QVXOQL0XZBB6hBRHcd0oGWIADD1UQXYPMjiNs/mdnrEIsBAZS /OUceGbMdWeuOA3uvd3n8jmpzPSCk2qyYJVE7lowqVqPaBtMYeax/NCvYBPWn/nAklX2 GUe3rqVEmhN0WzcqKpbR0AD0efii9vgySKLfe/dQTvNuhwm+ufJA+IV92wxSrc81KROB dFoRNaHqrE8maReJcmwGAv2ve/yNYBDlOZVQi+Z70ReqqerXAE9xAUhHFInQif1se2op PCfvbKYL7KXsVQsdS7jAvW2ygcYiWSsiprH2Hon48YaAQBGyjYzEpfZgna9h9wwr5CcL 4MFQ== X-Forwarded-Encrypted: i=1; AJvYcCWSKrJ0ZOKc5WwXxZO7jBV9ZvoyumcXKDBzxYUJu2Wj5VDw/ehhnmpPvA3W3ZTu9/AquF5hJRtb+AxwLNo=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2D2iRZ5YPhyvz7cCAvj0yr/Ay7cn6UaLHuFTJXBOLDk9mTiSc NnVtkh5MAFwKh3dsHs9IOnhshN6s1Sg+KNODgOgYT8LO7XiHVK4XK4Z0AerKhtO38LWD86Nvzkz 2 X-Google-Smtp-Source: AGHT+IG3fu0AcNyUIzJ/75A6XmoJKAgZCtU5+fN/L99HtW09ex7tvaGVLFa8UCS6eaNGUaRKbqlz0X7DUhU= X-Received: from plcy20.prod.google.com ([2002:a17:903:114:b0:224:13ec:ae57]) (user=yabinc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:eb8a:b0:219:e4b0:4286 with SMTP id d9443c01a7336-22c319f77e6mr3968165ad.29.1744742822049; Tue, 15 Apr 2025 11:47:02 -0700 (PDT) Date: Tue, 15 Apr 2025 11:46:49 -0700 In-Reply-To: <20250415184649.356683-1-yabinc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250415184649.356683-1-yabinc@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250415184649.356683-3-yabinc@google.com> Subject: [PATCH v4 2/2] coresight: core: Disable helpers for devices that fail to enable From: Yabin Cui To: Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , Jie Gan , Alexander Shishkin Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yabin Cui Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When enabling a SINK or LINK type coresight device fails, the associated helpers should be disabled. Signed-off-by: Yabin Cui Suggested-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index fb43ef6a3b1f..d9fcea69d221 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -486,8 +486,10 @@ int coresight_enable_path(struct coresight_path *path,= enum cs_mode mode, * that need disabling. Disabling the path here * would mean we could disrupt an existing session. */ - if (ret) + if (ret) { + coresight_disable_helpers(csdev, path); goto out; + } break; case CORESIGHT_DEV_TYPE_SOURCE: /* sources are enabled from either sysFS or Perf */ @@ -497,15 +499,17 @@ int coresight_enable_path(struct coresight_path *path= , enum cs_mode mode, child =3D list_next_entry(nd, link)->csdev; ret =3D coresight_enable_link(csdev, parent, child, source); if (ret) - goto err; + goto err_disable_helpers; break; default: - goto err; + goto err_disable_helpers; } } =20 out: return ret; +err_disable_helpers: + coresight_disable_helpers(csdev, path); err: coresight_disable_path_from(path, nd); goto out; --=20 2.49.0.604.gff1f9ca942-goog