Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp59467pja; Fri, 22 Nov 2019 03:26:29 -0800 (PST) X-Google-Smtp-Source: APXvYqyBHAPlOnODahyEeR0biuL1DpgBBxgPY2uo+hiho3KAJsxwCyokfPcCu1l0lmXn7x/GaOhl X-Received: by 2002:a17:906:814a:: with SMTP id z10mr1427349ejw.62.1574421989271; Fri, 22 Nov 2019 03:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421989; cv=none; d=google.com; s=arc-20160816; b=LGLcGZnWQOmwTvcGmjTtf3siT8APkkQ8rliPpd1FerUh1ngcx9+G2f1gDlllXbphzq Gsddiz0+LZsr6Wwohd9swZpFaaFfOpr1junIZpRisLDHbSxIgp7kEc449ZamdXf+kB2K N6nINpR9jmj8CVtxcoj2WMiulbEDwkffNAq0ok3p6B5o4nQKwyny0x1yZb6wyYcL2m2S 8FG7G1VcO+UtqQEa1a/ALcNWjXIqGy+xu1gmAvmPBKy7PRFgtTb1MKivR8BV4WL2mqIp VbZa4+K7Q8cF2OevQgRJKZHxmbto+AZO3dZ42k5jkBudAZuhJJ7xS5d1UDx9e0lz/5y7 kGRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MEuiMn5xXhzKoAz8rqlknXvkGCSpLwXbW73JQTweZ44=; b=Vjz8pnDkpRI+oPa+VPzTg+ywu5YMHrnvD47c4KsnVgY6TbjpZoQEY2osWrE3kwOjQo 0Gub1lQotzelvDo0BG8G6ncXhCcDSiRGAsbN8N+KaeNlan1JgM3whE3zvh6tyz8V7bT1 +vEX+ZX02LcJyo4/3XKJwT5OlEZTtWTH4HJKOAmnEIHhfn7xNN9fk4H+goZdy4aAWArW 7h5BUUPk1Lvxk4gQrCE516ckFEocOJc/nhT+xii6sGyCBQB4w8w6tdn/LNqpiBmN0CXp c4MSxSNowjXo151ASJZY7cCF5/4qFOqgshgf6u2vyXd7qaC/USTLzN+gWAI74eu8X49w l29w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QWUdv5xx; 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 w24si1880962edu.376.2019.11.22.03.26.06; Fri, 22 Nov 2019 03:26:29 -0800 (PST) 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=@kernel.org header.s=default header.b=QWUdv5xx; 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 S1727269AbfKVKok (ORCPT + 99 others); Fri, 22 Nov 2019 05:44:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:50542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727740AbfKVKog (ORCPT ); Fri, 22 Nov 2019 05:44:36 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B1DD7205C9; Fri, 22 Nov 2019 10:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574419474; bh=xfI8/dPVmCK1BenNrBBdSQzPPGYrx8ypbcs/wGBHDaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QWUdv5xx89L1G6ez34799qyJJ7g4yZn1VSaZ6Rd60b6BzqUvhStHEm1KQoqALU7ef nFnzfeWDa/4wA4e82Fnpy6CL0fYUTPBhU+BDzDL4IIoZYNU3liN3bW79vdkQrtHhp+ XJ/qS7EtaoC6RpmfSb4G1ixx68mWCIYF8Uop1HS4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathieu Poirier , Suzuki K Poulose , Sasha Levin Subject: [PATCH 4.9 117/222] coresight: Fix handling of sinks Date: Fri, 22 Nov 2019 11:27:37 +0100 Message-Id: <20191122100911.607425908@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100830.874290814@linuxfoundation.org> References: <20191122100830.874290814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 c71369de02b285d9da526a526d8f2affc7b17c59 ] The coresight components could be operated either in sysfs mode or in perf mode. For some of the components, the mode of operation doesn't matter as they simply relay the data to the next component in the trace path. But for sinks, they need to be able to provide the trace data back to the user. Thus we need to make sure that "mode" is handled appropriately. e.g, the sysfs mode could have multiple sources driving the trace data, while perf mode doesn't allow sharing the sink. The coresight_enable_sink() however doesn't really allow this check to trigger as it skips the "enable_sink" callback if the component is already enabled, irrespective of the mode. This could cause mixing of data from different modes or even same mode (in perf), if the sources are different. Also, if we fail to enable the sink while enabling a path (where sink is the first component enabled), we could end up in disabling the components in the "entire" path which were not enabled in this trial, causing disruptions in the existing trace paths. Cc: Mathieu Poirier 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 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 398e44a9ec45d..5ffabc388630e 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -132,12 +132,14 @@ static int coresight_enable_sink(struct coresight_device *csdev, u32 mode) { int ret; - if (!csdev->enable) { - if (sink_ops(csdev)->enable) { - ret = sink_ops(csdev)->enable(csdev, mode); - if (ret) - return ret; - } + /* + * We need to make sure the "new" session is compatible with the + * existing "mode" of operation. + */ + if (sink_ops(csdev)->enable) { + ret = sink_ops(csdev)->enable(csdev, mode); + if (ret) + return ret; csdev->enable = true; } @@ -331,8 +333,14 @@ int coresight_enable_path(struct list_head *path, u32 mode) switch (type) { case CORESIGHT_DEV_TYPE_SINK: ret = coresight_enable_sink(csdev, mode); + /* + * Sink is the first component turned on. If we + * failed to enable the sink, there are no components + * that need disabling. Disabling the path here + * would mean we could disrupt an existing session. + */ if (ret) - goto err; + goto out; break; case CORESIGHT_DEV_TYPE_SOURCE: /* sources are enabled from either sysFS or Perf */ -- 2.20.1