From patchwork Thu Apr 25 19:52:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 162866 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2362481jan; Thu, 25 Apr 2019 12:53:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUPVhKcJg8C7y2h/+WooNA4U9kxrSCdt0fffKW1YDjTMI38zBUpSbxBCNDg6/igVXVq39S X-Received: by 2002:a63:ef53:: with SMTP id c19mr15923029pgk.120.1556222025767; Thu, 25 Apr 2019 12:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556222025; cv=none; d=google.com; s=arc-20160816; b=QeTanxsdWogxWVVbxHUbUAb43P3QyoF7Nz8Dq5cOjkkccH35ajVbZoihR3p7TO/BGz tWv0hOa68WL+9DMFO80+eBT+SC3b8vArXeOuDj2n5vAYVNiCDRHA9Bg0Otw9gcIuP60U ntL8EAUOKoJ5QxdoykEEjjkDA7+6CVUHcU9X/vwhJanG8pHrlV4Kp8hlPEUFAXdshCiV 634LBwhGOmryPCbu/mUeQLjkXWoD08Dpz9XSe+nhijh7+TMA1UmAE1Z6YR2XZo3bo9BC sy0fOrswdpx0H4grg11qJPsbWFmq1fYILwvwzhTfpxgX5stUW9q650FV8DGSMtsCffsB w7Og== 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=aWyPwAmKiV26NYLJXz5kLa0RrGlpEkg6p1STyf3/JXM=; b=Bwc7g6jS92QMSSRylpvvil6SUGcnVZuZwow81SxMhusnGKcMT9D4R6Ew1dJewdlXSI VhDOKMBh4njAFLVRGE5Mg6yX1M/vtJGcDDoGx/VurL4t/5kjbjdbpDAyymuBmITUzMQ6 KaEdWvQUAHDzXLPHE55AKgpxHNfGFe8umCw3/E93ALTKRt06RSaCzm7a5SFUvajQ8aHy f3cNdn200IhXkZqF+9m67uF611XuXdE0jyQtw4Ulq25V0krqXa5lO/xNVQHJsqTNC0Zi Xy+Q39gxMe5I7xr03ht+I8oERlczoO1k8MXB8EG4LZ73ZyVywqP4GvOTkA0IahhnRHPH XFCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UIgR3XfD; 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 l3si21329230pgj.136.2019.04.25.12.53.45; Thu, 25 Apr 2019 12:53:45 -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=UIgR3XfD; 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 S1730705AbfDYTxn (ORCPT + 30 others); Thu, 25 Apr 2019 15:53:43 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40524 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730554AbfDYTxj (ORCPT ); Thu, 25 Apr 2019 15:53:39 -0400 Received: by mail-pg1-f195.google.com with SMTP id d31so362307pgl.7 for ; Thu, 25 Apr 2019 12:53:38 -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=aWyPwAmKiV26NYLJXz5kLa0RrGlpEkg6p1STyf3/JXM=; b=UIgR3XfDDDzlPAaFcdmVGS/UsH5wKZ2stJgoDKiDZvU43v/jj9cr1xMDDycXQfY3be TAwGdyxr79UKVJTctTA/NP+5MwI4M/WPzDDSESW5gQRoV+5MYuql8N+mObfahbPH3pMD MLaL6FB298a5B9frgl5taSPFFDsCmOllhgZ6soIAP1Li5EZL5PVS/TcDMkHQLNTdbvUf cEDI4I7QvckjAYEzx3ZXbVD8HXATG71aoFLXV8C/FAeTtXpHKi60X6rDYU9SCurxq3Rp N9WAlkv2D47743FUkV/poVG48HlfnRUdj3qJNvaneheg9Uwk5s4uy0wl547AhFQDfZeF GnqA== 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=aWyPwAmKiV26NYLJXz5kLa0RrGlpEkg6p1STyf3/JXM=; b=cp0aqUpHElChOWvndOLKBdTwXo3T7BYRUHAJ+uK+dzmeA5Yu5uSP3XKxr7HUpbvQx+ XqDOFu+zSEFiABZMsFNLcHMEE/AZYgci71xQEVUQjdPSt6ZlzK159sIikuK1ruO+cJ8R x85J/dPeo6Vy36uQxceZpRckrIjLYx/FoRnIHnL6q3U3Hq0fbxFNfcwKpsqKsj94FfmP cy+lGqTOzHmUtzsqirFi0OIfIOJfhMvO4D6cpc3aUlP2CreuyQE4Gyj2DelNjsbm5Y1H NwOT6lzZPrat+B3LyY5rrggGzGMmLT7+SOYiuWDrmvwoHiCnKj6iA2K1mrcyEgXP54kJ 651A== X-Gm-Message-State: APjAAAV+eZ5noQdD4UNGmUKE463rZNehYcWZfdTUzp8Apl1i4ufmQDOb juE98bQXYB4KhxCdmRfhHpvwFg== X-Received: by 2002:a65:63cb:: with SMTP id n11mr7252692pgv.236.1556222018564; Thu, 25 Apr 2019 12:53:38 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id t64sm47261961pfa.86.2019.04.25.12.53.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 12:53:37 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 20/32] coresight: Properly address concurrency in sink::update() functions Date: Thu, 25 Apr 2019 13:52:58 -0600 Message-Id: <20190425195310.31562-21-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190425195310.31562-1-mathieu.poirier@linaro.org> References: <20190425195310.31562-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When operating in CPU-wide trace scenarios and working with an N:1 source/sink HW topology, update() functions need to be made atomic in order to avoid racing with start and stop operations. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose Tested-by: Leo Yan Tested-by: Robert Walker --- drivers/hwtracing/coresight/coresight-etb10.c | 4 +++- drivers/hwtracing/coresight/coresight-tmc-etf.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 6b73bc2e0dbd..00d664c6a401 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -405,7 +405,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, const u32 *barrier; u32 read_ptr, write_ptr, capacity; u32 status, read_data; - unsigned long offset, to_read; + unsigned long offset, to_read, flags; struct cs_buffers *buf = sink_config; struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -414,6 +414,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, capacity = drvdata->buffer_depth * ETB_FRAME_SIZE_WORDS; + spin_lock_irqsave(&drvdata->spinlock, flags); __etb_disable_hw(drvdata); CS_UNLOCK(drvdata->base); @@ -524,6 +525,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, } __etb_enable_hw(drvdata); CS_LOCK(drvdata->base); + spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read; } diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index 30f868676540..a38ad2b0d95a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -413,7 +413,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, u32 *buf_ptr; u64 read_ptr, write_ptr; u32 status; - unsigned long offset, to_read; + unsigned long offset, to_read, flags; struct cs_buffers *buf = sink_config; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -424,6 +424,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, if (WARN_ON_ONCE(drvdata->mode != CS_MODE_PERF)) return 0; + spin_lock_irqsave(&drvdata->spinlock, flags); CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); @@ -517,6 +518,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, to_read = buf->nr_pages << PAGE_SHIFT; } CS_LOCK(drvdata->base); + spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read; }