Received: by 10.192.165.156 with SMTP id m28csp1105336imm; Wed, 11 Apr 2018 12:30:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/QkJTjnKU/AuQqQcLkirPoHV0SLdGYBI63c3pC6js7j7CcIEkVOMrYjxeuFB/QBSSxjI8V X-Received: by 10.98.157.7 with SMTP id i7mr5001141pfd.85.1523475047228; Wed, 11 Apr 2018 12:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523475047; cv=none; d=google.com; s=arc-20160816; b=tmpxgWnOdgdZLF4DWWD/Pa3sphgVt5rJiQeeMOyghk2c134bUeR9FXABPcDqa5nsGR aluoxs/QmMY+r1GO9dSgg+CdCrsmvnCpXA5XYzQeOh3AlvEipixc8bMM97I8aGFTkTqx 4CipCKzD0SjUSR/bk5oKcALxfbwmdgzJdXw3e6wcVMRMXu3XE+7ZOytQz0YDRk7MLVJr HeA0OveJ0Br/16fHK5RYYmBFXbzcmFrb1hlnL1tDfl3MRYym1pbRgdeMt3kAhshYzeTC lAIqY6PL9isxqanBjiVTKdXnaHOC602AdSut5PpH4NK+s6v4hqUY967KBd9p3lpGjD+F pldA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=62hqTOe5x8sZvMeWHP+vUE5YhqV6MXijX2cGx5paJj0=; b=cisOPFfsYeP+Ik/oI1kirZm4mmp+OgIlFog3D8D/VGSzqb++3LJeZqgWKkwUhMvNKJ KVJLGBc8nNp6+gYC0atssHVYm2t67YG6cQDpY4giqQckHKPYIFQGxxWUWwfyr3s4Eh8q 71+/fPI43MEqWIDiWbaejCMTeXm1cgKfwuc9Pc62qgZBfaJtoQxR+QHl5iGEqITOjbVy sDJ9j1RfdNPctQbVjZKtdvXwi07ih/Cp0uCC3rkk92Ll4ccd+MHJLm3BAV+IW0ltC/Hb lmiGBXOXh6ZU/Ry+n8s/Fh9XQ5D8RbvUYWhaNIzu/nB0BNSgN8N1qCf2+/6iV2fRSXJS 6Yhw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t14si1345791pfg.225.2018.04.11.12.30.09; Wed, 11 Apr 2018 12:30:47 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755523AbeDKT1e (ORCPT + 99 others); Wed, 11 Apr 2018 15:27:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38824 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933692AbeDKTDJ (ORCPT ); Wed, 11 Apr 2018 15:03:09 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E70A2E4D; Wed, 11 Apr 2018 19:03:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathieu Poirier , Robert Walker , Suzuki K Poulose , Sasha Levin Subject: [PATCH 4.9 230/310] coresight: Fix reference count for software sources Date: Wed, 11 Apr 2018 20:36:09 +0200 Message-Id: <20180411183632.403871237@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/coresight/coresight.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -498,6 +498,9 @@ int coresight_enable(struct coresight_de { int cpu, ret = 0; struct list_head *path; + enum coresight_dev_subtype_source subtype; + + subtype = csdev->subtype.source_subtype; mutex_lock(&coresight_mutex); @@ -505,8 +508,16 @@ int coresight_enable(struct coresight_de if (ret) goto out; - 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 == CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE) + atomic_inc(csdev->refcnt); goto out; + } path = coresight_build_path(csdev); if (IS_ERR(path)) { @@ -523,7 +534,7 @@ int coresight_enable(struct coresight_de if (ret) goto err_source; - switch (csdev->subtype.source_subtype) { + switch (subtype) { case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: /* * When working from sysFS it is important to keep track