From patchwork Wed Jun 13 02:01:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 9255 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2826D23E37 for ; Wed, 13 Jun 2012 02:02:23 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id ED1CDA183A2 for ; Wed, 13 Jun 2012 02:02:22 +0000 (UTC) Received: by mail-gg0-f180.google.com with SMTP id f1so52452ggn.11 for ; Tue, 12 Jun 2012 19:02:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding :x-content-scanned:x-cbid:x-gm-message-state; bh=TnLaMPp3D6waSATjWBm1e6AvXu/apemmvD3QvyNQbu8=; b=a5KMIk0DTsMge3H8+ggqAaIFAwWAgZjrJNQz0niYyL03WmR1bs97FKGhXcrqH1THny EsMQW0+SJ32sB4bBKJ65an8hz5bW3YFXr0YYQZINJ7GUnLVvPII990Vi99R/r7xOHe0T zfKpQ6GG5fSBsqH5hNZXdB6sEeQROGdyja34Qhi+HQp0mBa2igdpzW4pUub0AcIjVbi7 BJ1SwpUEebht0dkaK6YKlMU7qccp/wWs3Vp2BYqCgSq4j7nz96QfPGRJXLix+hwoiZlx f+e0zz4hPFG8NFnR7jxioXktMvxLdYkvU6i1NGNcoU9gz8oJ6Mmcus8SiVFeUcj/kYAG MHkQ== Received: by 10.50.203.39 with SMTP id kn7mr9588939igc.53.1339552942421; Tue, 12 Jun 2012 19:02:22 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp200457ibb; Tue, 12 Jun 2012 19:02:21 -0700 (PDT) Received: by 10.68.236.129 with SMTP id uu1mr44908781pbc.77.1339552941627; Tue, 12 Jun 2012 19:02:21 -0700 (PDT) Received: from e37.co.us.ibm.com (e37.co.us.ibm.com. [32.97.110.158]) by mx.google.com with ESMTPS id hc10si4950613pbc.61.2012.06.12.19.02.21 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 12 Jun 2012 19:02:21 -0700 (PDT) Received-SPF: pass (google.com: domain of jstultz@us.ibm.com designates 32.97.110.158 as permitted sender) client-ip=32.97.110.158; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jstultz@us.ibm.com designates 32.97.110.158 as permitted sender) smtp.mail=jstultz@us.ibm.com Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 12 Jun 2012 20:02:20 -0600 Received: from d01dlp03.pok.ibm.com (9.56.224.17) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 12 Jun 2012 20:02:10 -0600 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 99875C9005A; Tue, 12 Jun 2012 22:02:08 -0400 (EDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q5D227tQ230374; Tue, 12 Jun 2012 22:02:08 -0400 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q5D225P2022572; Tue, 12 Jun 2012 20:02:06 -0600 Received: from kernel.beaverton.ibm.com (kernel.beaverton.ibm.com [9.47.67.96]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q5D224Aq022462; Tue, 12 Jun 2012 20:02:04 -0600 Received: by kernel.beaverton.ibm.com (Postfix, from userid 1056) id 0D594C0627; Tue, 12 Jun 2012 19:01:41 -0700 (PDT) From: John Stultz To: LKML Cc: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Russell King , Paul Gortmaker , Alexander Shishkin , Mathieu Poirier , John Stultz Subject: [PATCH 06/15] ARM: etm: Add some missing locks and error checks Date: Tue, 12 Jun 2012 19:01:24 -0700 Message-Id: <1339552887-17204-7-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.3.2.146.gca209 In-Reply-To: <1339552887-17204-1-git-send-email-john.stultz@linaro.org> References: <1339552887-17204-1-git-send-email-john.stultz@linaro.org> MIME-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12061302-7408-0000-0000-000005CDFD38 X-Gm-Message-State: ALoCoQn7BM2flfTcluDX0qe0qq1u583Q1k8GcIJA4PwKskJ1LgpMq3gj7PV8AURjf5fDkdwBLuDr From: Arve Hjønnevåg It is not safe to call etm_lock or etb_lock without holding the mutex since another thread may also have unlocked the registers. Also add some missing checks for valid etb_regs in the etm sysfs entries. CC: Russell King CC: Paul Gortmaker CC: Alexander Shishkin CC: Mathieu Poirier Acked-by: Alexander Shishkin Signed-off-by: Arve Hjønnevåg Signed-off-by: John Stultz --- arch/arm/kernel/etm.c | 57 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 39 insertions(+), 18 deletions(-) diff --git a/arch/arm/kernel/etm.c b/arch/arm/kernel/etm.c index c651cf9..3d21cf6 100644 --- a/arch/arm/kernel/etm.c +++ b/arch/arm/kernel/etm.c @@ -264,8 +264,13 @@ static void etm_dump(void) static void sysrq_etm_dump(int key) { + if (!mutex_trylock(&tracer.mutex)) { + printk(KERN_INFO "Tracing hardware busy\n"); + return; + } dev_dbg(tracer.dev, "Dumping ETB buffer\n"); etm_dump(); + mutex_unlock(&tracer.mutex); } static struct sysrq_key_op sysrq_etm_op = { @@ -374,6 +379,7 @@ static int __devinit etb_probe(struct amba_device *dev, const struct amba_id *id if (ret) goto out; + mutex_lock(&t->mutex); t->etb_regs = ioremap_nocache(dev->res.start, resource_size(&dev->res)); if (!t->etb_regs) { ret = -ENOMEM; @@ -382,6 +388,16 @@ static int __devinit etb_probe(struct amba_device *dev, const struct amba_id *id amba_set_drvdata(dev, t); + etb_unlock(t); + t->etb_bufsz = etb_readl(t, ETBR_DEPTH); + dev_dbg(&dev->dev, "Size: %x\n", t->etb_bufsz); + + /* make sure trace capture is disabled */ + etb_writel(t, 0, ETBR_CTRL); + etb_writel(t, 0x1000, ETBR_FORMATTERCTRL); + etb_lock(t); + mutex_unlock(&t->mutex); + etb_miscdev.parent = &dev->dev; ret = misc_register(&etb_miscdev); @@ -395,25 +411,19 @@ static int __devinit etb_probe(struct amba_device *dev, const struct amba_id *id else clk_enable(t->emu_clk); - etb_unlock(t); - t->etb_bufsz = etb_readl(t, ETBR_DEPTH); - dev_dbg(&dev->dev, "Size: %x\n", t->etb_bufsz); - - /* make sure trace capture is disabled */ - etb_writel(t, 0, ETBR_CTRL); - etb_writel(t, 0x1000, ETBR_FORMATTERCTRL); - etb_lock(t); - dev_dbg(&dev->dev, "ETB AMBA driver initialized.\n"); out: return ret; out_unmap: + mutex_lock(&t->mutex); amba_set_drvdata(dev, NULL); iounmap(t->etb_regs); + t->etb_regs = NULL; out_release: + mutex_unlock(&t->mutex); amba_release_regions(dev); return ret; @@ -475,7 +485,10 @@ static ssize_t trace_running_store(struct kobject *kobj, return -EINVAL; mutex_lock(&tracer.mutex); - ret = value ? trace_start(&tracer) : trace_stop(&tracer); + if (!tracer.etb_regs) + ret = -ENODEV; + else + ret = value ? trace_start(&tracer) : trace_stop(&tracer); mutex_unlock(&tracer.mutex); return ret ? : n; @@ -491,18 +504,25 @@ static ssize_t trace_info_show(struct kobject *kobj, u32 etb_wa, etb_ra, etb_st, etb_fc, etm_ctrl, etm_st; int datalen; - etb_unlock(&tracer); - datalen = etb_getdatalen(&tracer); - etb_wa = etb_readl(&tracer, ETBR_WRITEADDR); - etb_ra = etb_readl(&tracer, ETBR_READADDR); - etb_st = etb_readl(&tracer, ETBR_STATUS); - etb_fc = etb_readl(&tracer, ETBR_FORMATTERCTRL); - etb_lock(&tracer); + mutex_lock(&tracer.mutex); + if (tracer.etb_regs) { + etb_unlock(&tracer); + datalen = etb_getdatalen(&tracer); + etb_wa = etb_readl(&tracer, ETBR_WRITEADDR); + etb_ra = etb_readl(&tracer, ETBR_READADDR); + etb_st = etb_readl(&tracer, ETBR_STATUS); + etb_fc = etb_readl(&tracer, ETBR_FORMATTERCTRL); + etb_lock(&tracer); + } else { + etb_wa = etb_ra = etb_st = etb_fc = ~0; + datalen = -1; + } etm_unlock(&tracer); etm_ctrl = etm_readl(&tracer, ETMR_CTRL); etm_st = etm_readl(&tracer, ETMR_STATUS); etm_lock(&tracer); + mutex_unlock(&tracer.mutex); return sprintf(buf, "Trace buffer len: %d\nComparator pairs: %d\n" "ETBR_WRITEADDR:\t%08x\n" @@ -652,7 +672,6 @@ static int __devinit etm_probe(struct amba_device *dev, const struct amba_id *id amba_set_drvdata(dev, t); - mutex_init(&t->mutex); t->dev = &dev->dev; t->flags = TRACER_CYCLE_ACC | TRACER_TRACE_DATA; t->etm_portsz = 1; @@ -746,6 +765,8 @@ static int __init etm_init(void) { int retval; + mutex_init(&tracer.mutex); + retval = amba_driver_register(&etb_driver); if (retval) { printk(KERN_ERR "Failed to register etb\n");