Received: by 10.213.65.68 with SMTP id h4csp2119467imn; Sun, 8 Apr 2018 20:11:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/7jh+oI+0XRa/2Lgsud7BA5PfLi0HhbyBO2R/wf7khjwd3l5oiRqm1i929/Or1G9nmVIf X-Received: by 2002:a17:902:525:: with SMTP id 34-v6mr36562541plf.267.1523243388151; Sun, 08 Apr 2018 20:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243388; cv=none; d=google.com; s=arc-20160816; b=DFpvyKs93dfQS+Wn7Rljbu9TKc3Ni5oXaH+37iZIMxIemHyZ9eUzn74ZD8adXYLfFF 6vFfwjC+fdqtVr7B5Hpa5Kcqjn+5JQQnx8ngb2qV6IFIrNoMz0UIDBBu0YiaODJ8GZSd YRaJSPXFxarZmRW30htoRrhahjfjeW6dQPrbU4SnwJEU1eKwt6RGbq4j7uMzAYKnlI2f vnC9CxG4iN/S+3A9Sr+tq3xdx5+Z33t+36/s+CN9akRJoMAgUY51tIa6Auz/HviLejLw Gzqx7l214/yT3gu08viRpEzzaV+GvvodEzrKK33OW/z5HcEAQ1ILOmOAXx869iRdbRHW SfEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=2ryWCcpzvTqVZnEp2VrgJ+OXBI5PJDwrMzQXP0zoAnI=; b=tVLPDBTyxVDIHDk0bBsOPHHi1WHDGOlrk+CMc+zwz+471wW96MGhN8hrI6bxFkw0mQ d4ruou+c+6Wv9nP1p3WHfPIamFr4cah/PJzIKBjj+hXlUTc56aLgkwWUBhpv16b142RN egH8hYtGz+mOvLTxn2I7v9WVm6fYtCv+QGKgf4LrecYofRDkd261AvC4AKlCJkXW3dKl eWDBWskbnYAJYPAX9nC7C2JFy333P0KtLodLJZ4CdIhNPMr6QRkYc02MtbKwERPAgIFB dJRCpBOaVFfHSnA4WDZWV3SvLxxpX/hU0Sz5WLYodrH/gyWZpMYs2uaq+hWCHj53/Zd5 EY7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=XSfElTo1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z73si10557440pgz.559.2018.04.08.20.09.10; Sun, 08 Apr 2018 20:09:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=XSfElTo1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758060AbeDICno (ORCPT + 99 others); Sun, 8 Apr 2018 22:43:44 -0400 Received: from mail-by2nam03on0133.outbound.protection.outlook.com ([104.47.42.133]:46250 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755442AbeDIA0s (ORCPT ); Sun, 8 Apr 2018 20:26:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=2ryWCcpzvTqVZnEp2VrgJ+OXBI5PJDwrMzQXP0zoAnI=; b=XSfElTo1GGdzLwJ7ezrCAh4CVwTEdm/Ht1vQNgwicseYV0MPSN3q8i1FKxqr3LcBcLfzrZ0epuKO8a/3P9+fsO8nankodW4r0qkIlwIawQmDSdEVzrp44DVvqnBiSZ94xPL+3+X7xOVflPLdp/NOpROznA8JUfcQqXwA8rbwAFk= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0885.namprd21.prod.outlook.com (52.132.132.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:26:42 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:26:42 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Suzuki K Poulose , Mathieu Poirier , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 021/293] coresight: Fix reference count for software sources Thread-Topic: [PATCH AUTOSEL for 4.9 021/293] coresight: Fix reference count for software sources Thread-Index: AQHTz5juRR8fuS0wuUGF4s8gRqbvOw== Date: Mon, 9 Apr 2018 00:23:06 +0000 Message-ID: <20180409002239.163177-21-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0885;7:xKyHSLUFDRUue0yZ19MRDLvH3bsBLphjpfxnrvx+pC/yr1NeXMtDtFca+YiAMrAjWIeNXC6hgVJ/rOUT8y4fGNo8yUsihWrstnwH8RJUrdVyYHOD2ds2QJCxq0BKhNzdWIMvdx8QZ6I8u7zMXYpDU0r1YJnzP1L8hq3gstA+k1n89V3jOCFmpEVcL0Q7nY6au0yew7U0ky5bRq5U3w//tmAzWifVr7HEXjvTbV892HstQrOEpBm989tA4Oy99axw;20:pYKNQpSeMwOEhAsfTU+IAApghoEypNfo43Xg5/hYtK8aeyUQ7hraxnEqYd6P1g09tWpoim5B3dyYfz6fjJgmBL0me3a2SGOwRs/jTENOUkoEE6K/MjSNYKaeSIBVO5VHP8Vkg+gacqPdgiNJW/2sDIvH5//u37MKiQgCBMgeDdw= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: af7c97e1-1ea3-4500-08c5-08d59db09165 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0885; x-ms-traffictypediagnostic: DM5PR2101MB0885: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(278428928389397)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0885;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0885; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(346002)(376002)(396003)(39380400002)(189003)(199004)(2906002)(68736007)(22452003)(316002)(6512007)(5660300001)(6666003)(54906003)(110136005)(486006)(6486002)(102836004)(36756003)(14454004)(99286004)(86612001)(105586002)(72206003)(106356001)(2900100001)(1076002)(97736004)(10090500001)(3280700002)(5250100002)(6436002)(3660700001)(6116002)(575784001)(3846002)(305945005)(86362001)(59450400001)(66066001)(10290500003)(186003)(81166006)(8936002)(478600001)(476003)(25786009)(81156014)(8676002)(4326008)(7736002)(2501003)(107886003)(6506007)(2616005)(26005)(76176011)(446003)(53936002)(11346002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0885;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: TLAdVloJdDxUUlSiKGjDyaOTJITyjx874i5TIuY6noDlI6DPjZr5xXSCnQYYjonj88q/VOQ+if7hum8DfWIWa/QZWXYXQ+rfZFMQEp3EDazAAmPx+FbY0UQ90yqxt7hizZv81GhGMRd4llMM4lfSfz4C5vZDoF9elYjCHMYQokBytsC3defmQiyCi1jvbuaTDSEFnOKt5lEnJnSqL37DmxXMzbzPf2yx0mTfUM6UBBy/fjSCFlTQ3sGSGj4MHCdczm8ZE3vLNISFHae4lp0wHB5bBuDiH3yuISn36Xra9GxmgCIJoJiv+3JYaKtMz80gxUAtgvkvYVpJydYBZNUXpOTlLVC2FeQ2Z5fWwfOrVrK2BW1YJLT37b7mfcA96hDhzykPREBa6GpW5rO93JteRoUTqXKbCLT38ZQOH02qH8M= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: af7c97e1-1ea3-4500-08c5-08d59db09165 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:23:06.2529 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0885 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suzuki K Poulose [ Upstream commit 022aa1a81b778789ee7cf3124595854276a0330d ] For software sources (i.e STM), there could be multiple agents generating the trace data, unlike the ETMs. So we need to properly do the accounting for the active number of users to disable the device when the last user goes away. Right now, the reference counting is broken for sources as we skip the actions when we detect that the source is enabled. This patch fixes the problem by adding the refcounting for software sources, even when they are enabled. Cc: Mathieu Poirier Reported-by: Robert Walker Signed-off-by: Suzuki K Poulose Signed-off-by: Mathieu Poirier Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/hwtracing/coresight/coresight.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/co= resight/coresight.c index 7bf00a0beb6f..4383324ec01c 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -498,6 +498,9 @@ int coresight_enable(struct coresight_device *csdev) { int cpu, ret =3D 0; struct list_head *path; + enum coresight_dev_subtype_source subtype; + + subtype =3D csdev->subtype.source_subtype; =20 mutex_lock(&coresight_mutex); =20 @@ -505,8 +508,16 @@ int coresight_enable(struct coresight_device *csdev) if (ret) goto out; =20 - if (csdev->enable) + if (csdev->enable) { + /* + * There could be multiple applications driving the software + * source. So keep the refcount for each such user when the + * source is already enabled. + */ + if (subtype =3D=3D CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE) + atomic_inc(csdev->refcnt); goto out; + } =20 path =3D coresight_build_path(csdev); if (IS_ERR(path)) { @@ -523,7 +534,7 @@ int coresight_enable(struct coresight_device *csdev) if (ret) goto err_source; =20 - switch (csdev->subtype.source_subtype) { + switch (subtype) { case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: /* * When working from sysFS it is important to keep track --=20 2.15.1