From patchwork Thu Sep 20 19:18:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 147148 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2376604ljw; Thu, 20 Sep 2018 12:19:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbZ9NRTgR23pwimN4ToTkWfJmhdAGbElmK4C3wcH73tp14k7UoxyQmMkuMcPmcTtL5/3HHM X-Received: by 2002:a63:a012:: with SMTP id r18-v6mr32848645pge.166.1537471148882; Thu, 20 Sep 2018 12:19:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537471148; cv=none; d=google.com; s=arc-20160816; b=giTKtlgr4qxqOZiAb+NkqKJMohfaffxyiikisIzkg7wYCDO1ZZNw26V1RoZVZ5JARq RzzQm297QTF1h73uGF/yw8+M/ACsdudprYnVLtcI3vJ9DyBGRtlxAIJAfdQB7oy8g8XE dxZwfnybXfYcDJzy3OtLQgSSQIZxMltpT/e2Z778mm2UnxQLmKsMcdvyyLAMwckmdHGt njfIv+bVg4AMxg/vPsfG0853TfbE5V79AItpTWVlDGvkhgmImVAIH7+qz/zlcPhelSEt cKTMama13D4r9MkPlncqBKXjcVbT9o/l5Vk4lUIL0/gqN+MY1v9Al8VH1mIvcHNtnfsY sNWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Q9mLJUvfHW+9PF2qxnbjTL+mt+UjMYG0sP1kUgTlkaI=; b=0A6T5NU0r/RX1Fu5H4r9PF7oY7jJg2klFVpJI54OTiK6Y/ghgzW5m6OXkgUVTd/V0b e8Wy9kWJzFITfN0VUBcuBHOqMBnhmHsViVkrPEEUKhDLAtHdz6csBP0B+faJwmZRoXsO pxeH6W5LQczycH5zxNZ47D862y1kkC6FcGqFVsDWoe+KnqLIkb/r4xnXFRjMOdJ00JMk 2uKcbx27Q6U6dnP1e6mcA+NubVGXMztDz91F0++L1J8ZzZDj5vjurya7GAtaM+rQLkS9 l4B/mvM2zdxHWevE+9jo0IFSCg1ibG87lX/ssWMMPcRWixFpbQrkGwkrf8HUz4NIyZfc oPsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TfW41lWX; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g70-v6si27482159pfe.4.2018.09.20.12.19.08; Thu, 20 Sep 2018 12:19:08 -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=@linaro.org header.s=google header.b=TfW41lWX; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389003AbeIUBEE (ORCPT + 32 others); Thu, 20 Sep 2018 21:04:04 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40205 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388559AbeIUBED (ORCPT ); Thu, 20 Sep 2018 21:04:03 -0400 Received: by mail-pl1-f195.google.com with SMTP id s17-v6so4791470plp.7 for ; Thu, 20 Sep 2018 12:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q9mLJUvfHW+9PF2qxnbjTL+mt+UjMYG0sP1kUgTlkaI=; b=TfW41lWXkzMpJ0PmNgow0xQEYq8zI9c0HM/9UKI6yuBZc2HJpWvauqB21tF6R8Befe hNAoVUre1AYuNE6C04mPAD0B+v07j+CvCnwvdKpw1vC9bs7SIO67/Lr3qaWpEAjb1mf4 ps1Zq0jSJ3g/XFesSpbmzAB/gpI4r4/38m6F0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q9mLJUvfHW+9PF2qxnbjTL+mt+UjMYG0sP1kUgTlkaI=; b=o48zUlcrWWgy1nEWHjiaBI/pFms17ejUYBof+YhD8c1ZoJQHI8uMkrEU/MlX51XFG6 RltteUWbqPqvmiyVvXhpa1y93WW5jAsjaCJgJzgGH84Q25R+8Qu09anubV6+kyVhv9yC 74ESHC9YFcyK/gtumK6/kV57kEgZsFKve818hpziuI142N/9exET4xn6MMuigJyTL6Em psIZA5iQuMBpeOBycl+1QF9Fs7XQ+m99ZWLtWt0W+WuMPloZcQw8Kp5Q6TdruIHASFbR SOOyuxoawXeCt8v8/yU4EmWdOiVhVZx8l8E4eSwmIauN3C7Q8dMcwMGTMMgfa/AGzyVV oghA== X-Gm-Message-State: APzg51CKyA6S5wBtydvn32wag5KHr7BboOP4jBvdyL1eXq0kFVo5E264 l7U2ofLbfr/PSY7uJl+bOeDwjg== X-Received: by 2002:a17:902:163:: with SMTP id 90-v6mr40541725plb.322.1537471144953; Thu, 20 Sep 2018 12:19:04 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id k13-v6sm4424443pgf.37.2018.09.20.12.19.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Sep 2018 12:19:03 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 28/44] coresight: Handle failures in enabling a trace path Date: Thu, 20 Sep 2018 13:18:03 -0600 Message-Id: <1537471099-19781-29-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537471099-19781-1-git-send-email-mathieu.poirier@linaro.org> References: <1537471099-19781-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suzuki K Poulose coresight_enable_path() enables the components in a trace path from a given source to a sink, excluding the source. The operation is performed in the reverse order; the sink first and then backwards in the list. However, if we encounter an error in enabling any of the component, we simply disable all the components in the given path irrespective of whether we enabled some of the components in the enable iteration. This could interfere with another trace session if one of the link devices is turned off (e.g, TMC-ETF). So, we need to make sure that we only disable those components which were actually enabled from the iteration. This patch achieves the same by refactoring the coresight_disable_path to accept a "node" to start from in the forward order, which can then be used from the error path of coresight_enable_path(). With this change, we don't issue a disable call back for a component which didn't get enabled. This change of behavior triggers a bug in coresight_enable_link(), where we leave the refcount on the device and will prevent the device from being enabled forever. So, we also drop the refcount in the coresight_enable_link() if the operation failed. Also, with the refactoring, we always start after the first node (which is the "SOURCE" device) for disabling the entire path. This implies, we must not find a "SOURCE" in the middle of the path. Hence, added a WARN_ON() to make sure the paths we get are sane, rather than simply ignoring them. Cc: Mathieu Poirier Signed-off-by: Suzuki K Poulose Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index e73ca6af4765..f4f50753cf75 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -187,8 +187,10 @@ static int coresight_enable_link(struct coresight_device *csdev, if (atomic_inc_return(&csdev->refcnt[refport]) == 1) { if (link_ops(csdev)->enable) { ret = link_ops(csdev)->enable(csdev, inport, outport); - if (ret) + if (ret) { + atomic_dec(&csdev->refcnt[refport]); return ret; + } } } @@ -277,13 +279,21 @@ static bool coresight_disable_source(struct coresight_device *csdev) return !csdev->enable; } -void coresight_disable_path(struct list_head *path) +/* + * coresight_disable_path_from : Disable components in the given path beyond + * @nd in the list. If @nd is NULL, all the components, except the SOURCE are + * disabled. + */ +static void coresight_disable_path_from(struct list_head *path, + struct coresight_node *nd) { u32 type; - struct coresight_node *nd; struct coresight_device *csdev, *parent, *child; - list_for_each_entry(nd, path, link) { + if (!nd) + nd = list_first_entry(path, struct coresight_node, link); + + list_for_each_entry_continue(nd, path, link) { csdev = nd->csdev; type = csdev->type; @@ -303,7 +313,12 @@ void coresight_disable_path(struct list_head *path) coresight_disable_sink(csdev); break; case CORESIGHT_DEV_TYPE_SOURCE: - /* sources are disabled from either sysFS or Perf */ + /* + * We skip the first node in the path assuming that it + * is the source. So we don't expect a source device in + * the middle of a path. + */ + WARN_ON(1); break; case CORESIGHT_DEV_TYPE_LINK: parent = list_prev_entry(nd, link)->csdev; @@ -316,6 +331,11 @@ void coresight_disable_path(struct list_head *path) } } +void coresight_disable_path(struct list_head *path) +{ + coresight_disable_path_from(path, NULL); +} + int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data) { @@ -369,7 +389,7 @@ int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data) out: return ret; err: - coresight_disable_path(path); + coresight_disable_path_from(path, nd); goto out; }