From patchwork Thu Apr 4 03:35:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E86CF13B5 for ; Thu, 4 Apr 2019 03:52:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB17428571 for ; Thu, 4 Apr 2019 03:52:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8EB428A30; Thu, 4 Apr 2019 03:52:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 699BA28762 for ; Thu, 4 Apr 2019 03:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NtAPz1wflMXe/Bjw5AJJDi2XmKWKoCBe93nFqqVEdVk=; b=MMgZGd88kOR4QgOHbHoV0aLwPk /NxU8VvwO/h0gD35GmhNvGA5S3HFj3ZdpzsOO4Xl8oYA/4lJU+45cGDUsmPhOZ5aJIV8gfnjlmFiu FkKuQ0fUnFsF7Vl47BzDtj/r/pCg7Ita/IzRUDk5MDM2aE7W3Bn8KoQ1c16pYqoKFBHW6d/6zzWfs 1Lb1cVMiMiP+JXJ6X0ka74oB/fuVE2t777/lKVd1J+IkX248hbr+rJEtimzj/uXs1j7atzZKe1bcW 1OpU9VowO1nZWZJnDbpsFjLzENu/ggDeNs7HJ077KOekaqzQhlfgYgwWmwIPdwFMldKiOEQs5OZms hOQ7SbkQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtQq-0003rV-2U; Thu, 04 Apr 2019 03:52:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtQ3-0002DC-Ml for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 03:52:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Rp82OG+X/1qzhxgu7Opyhu1qYPCsjQeQJx+i+wMOyCE=; b=XaJdDK7Tu6ZpOTzzCyG58VTvp emt1Hl6U4e9eZL2oCMx7S3mSDG72xKnoC59vmzw4mjRKZy/kOM65WcQpU/rCDmLna/T9sCyHL/POF 8fslCkHb2Gv/7PEWJjO4rOqJZsBhr2gqrjO0QCfEg9bABa+4r7AX9CKi7/jlDb7W5igoVf37ypcUe U9gVEqoEYvpy18tlLo6eCsHxQ4wzS7r9nNxJUAxl6HTzgjI0b4X7VWaK8WpP9w7gOS+dH4hsOXjB5 tdo0UbsRLyrKMf6lXy3GXMpa+nJBvd2blYjFSsV9NtZOWi0SKYNhAs0pS/GqHTzoQOgTzAVPHZtb3 x9gdFiXMg==; Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtAp-0008F2-OB for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:21 +0000 Received: by mail-pl1-x644.google.com with SMTP id m10so426182plt.10 for ; Wed, 03 Apr 2019 20:36:19 -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=Rp82OG+X/1qzhxgu7Opyhu1qYPCsjQeQJx+i+wMOyCE=; b=uWXgpbR5YVsdh1tkDK3c5M04exY7enShlsPHkKIwIqAg0jQLEPod7MxEbk+H/2YFcz ewWG019xQA/Lf3qtj7FErkvgro8gloYUwKTnLt3zJBa0YkZg3/yTQKVP43a5ex9/trTj JBzE92biGwlCxAdYA4Hhd7E085uqcUxOGhHqXVKLUEl4vxT4Z8zQnRPzaTaP2iyonlxt YDL9xYwgQat52IAFAuTHfzAHEVwNW5QgWQSFHN5IkO1BrKu5PwOwmDA5YIz/O6wOhF8V BMusCcGqe0BdXZ24kQU/tmzfO11fxxnV68luRiypOvVdge7qwRy0Q64yE0uTA+KjOMcO L8Hw== 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=Rp82OG+X/1qzhxgu7Opyhu1qYPCsjQeQJx+i+wMOyCE=; b=IDM0NpoGS4vY88J4tAwj/YoNfMQyKS73knv7i/bQ8Yla8ob61FOp/2maxxAM4//ovL 7zhzPv5qOfwqqveazU39xNlZRExBQHSq2Iz4/+f5E3Kwa/3UlHtwnPeqGrSUtCDrfofn 64uaJTUAaKABHl/WC1OYusab6+GH41FGJKkkwPv+FALtfkc+2q12aszKlFCpvi+dKYtU BmLgqcxBY3h1Xu6H1slm4Ty9jDzo5cShqEpXj5QEa9fdRd6N2sF1VJcinoN+fJ3eHhE2 oh1UItSJSn8T+vyS+0Xc4fyQ2IMNgxXgVVyvz2CFrMapviDz4eHccf4y4KZVGj019gjj zlbA== X-Gm-Message-State: APjAAAU6+CZyon+u9FQcauGRRa3GVp72YVDVI0VBq0RHok/3rXYCW/gC gemYIcNgXRL5fd/NiXUH7exxj2GILjU= X-Google-Smtp-Source: APXvYqxnprVmjjSF2tnUy4v7IbtEfubrPIrN37Y9gmUqDHLVytF4Jl14psXToYqcyqwcjS/j3syzww== X-Received: by 2002:a17:902:5a2:: with SMTP id f31mr3721169plf.119.1554348977964; Wed, 03 Apr 2019 20:36:17 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:17 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 08/20] coresight: Properly address concurrency in sink::update() functions Date: Wed, 3 Apr 2019 21:35:29 -0600 Message-Id: <20190404033541.14072-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_043619_878088_B92B767C X-CRM114-Status: GOOD ( 13.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/hwtracing/coresight/coresight-etb10.c | 4 +++- drivers/hwtracing/coresight/coresight-tmc-etf.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 52b7d95ab498..6b50e781dc57 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -413,7 +413,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); @@ -422,6 +422,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); @@ -532,6 +533,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; }