From patchwork Tue Aug 25 07:52:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Roxell X-Patchwork-Id: 7069131 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 168059F344 for ; Tue, 25 Aug 2015 07:57:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1365220895 for ; Tue, 25 Aug 2015 07:57:32 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1988520892 for ; Tue, 25 Aug 2015 07:57:31 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZU94t-0000Qi-TP; Tue, 25 Aug 2015 07:55:31 +0000 Received: from mail-la0-f44.google.com ([209.85.215.44]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZU94q-00080l-0q for linux-arm-kernel@lists.infradead.org; Tue, 25 Aug 2015 07:55:29 +0000 Received: by labia3 with SMTP id ia3so28355062lab.3 for ; Tue, 25 Aug 2015 00:55:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=auqsfDZ8pqxL5LZ2PdkOIvq2Bl7Lu5doD5GUB/VSg/A=; b=EOApJSc7fqQ9O2P+AamIBgJEfvOHDsYcg1fr26xZdz+WX/WyYHGpOR7/tGpT41RLhA hySrVGmqzC9XOKUkL3SspmMyv4KeAhnxu9cvwoIkCdtAbK5OR6p0XDP+Mh96N2viMK/G SevEKBcCO/NDo4I7jEbAUlQaim8Fdwb5GhnKsXnoqLjKWx2DzdQcgADqayGr8OfqPhtG mrRvimwMlcwUKntd8l074cqnK/KG+wjhtT0XTmXX1yVVs58DTBqix0OVHO4xS+lRcWF8 GsIO4Tbcfx85uscbeiz/Jm9Q0TMvd3YB0vKqt73C4MwEV8sud/9YL9SKbh8NAq1nqj3R vNNA== X-Gm-Message-State: ALoCoQncJNuv+xe5v3HR8akvR9f+asqWFgoQNevtXcMkfPuaI1jAZJeijh9f1gVtfGwyJFG2hCbK X-Received: by 10.112.160.73 with SMTP id xi9mr24121908lbb.92.1440489304721; Tue, 25 Aug 2015 00:55:04 -0700 (PDT) Received: from localhost (c-b03670d5.07-21-73746f28.cust.bredbandsbolaget.se. [213.112.54.176]) by smtp.gmail.com with ESMTPSA id aw4sm5737087lbc.10.2015.08.25.00.55.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Aug 2015 00:55:03 -0700 (PDT) From: Anders Roxell To: kgene@kernel.org, k.kozlowski@samsung.com, wsa@the-dreams.de Subject: [PATCH] drivers: i2c: exynos5: irq spinlock rt-safe Date: Tue, 25 Aug 2015 09:52:05 +0200 Message-Id: <1440489125-20082-1-git-send-email-anders.roxell@linaro.org> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150825_005528_270118_CD6F97A0 X-CRM114-Status: GOOD ( 17.02 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: khilman@linaro.org, Anders Roxell , linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-i2c@vger.kernel.org, ch.naveen@samsung.com, linux-arm-kernel@lists.infradead.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-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The exynos5_i2c_message_start enables interrupts while holding the i2c lock which is sought by the irq handler. If an IRQ is received before this lock is released then a deadlock occurs. This is only seen on an RT patched kernel, due to the transformation of spinlocks into sleeping locks. By using raw_spinlocks here the same code can run in mainline or an RT patched kernel. No change for !RT kenrels [ 10.992238] kernel BUG at ../kernel/locking/rtmutex.c:998! [ 10.992243] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM [ 10.992250] Modules linked in: [ 10.992258] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.1.5-rt5 [ 10.992263] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [ 10.992268] task: ed880000 ti: ed888000 task.ti: ed888000 [ 10.992281] PC is at rt_spin_lock_slowlock+0xa4/0x2ec [ 10.992288] LR is at rt_spin_lock_slowlock+0x54/0x2ec [ 10.992296] pc : [] lr : [] psr: 60000193 [ 10.992296] sp : ed889a28 ip : ed880001 fp : 00000089 [ 10.992300] r10: ed889a28 r9 : c0f55654 r8 : 00000060 [ 10.992305] r7 : ed880000 r6 : 00000000 r5 : 00000001 r4 : ed9f7288 [ 10.992310] r3 : ed880000 r2 : 00000000 r1 : ed880000 r0 : 00000000 [ 10.992316] Flags: nZCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment kernel ... ... [ 10.992662] [] (rt_spin_lock_slowlock) from [] (exynos5_i2c_irq+0x20/0x2b0) [ 10.992678] [] (exynos5_i2c_irq) from [] (handle_irq_event_percpu+0x68/0x158) [ 10.992690] [] (handle_irq_event_percpu) from [] (handle_irq_event+0x68/0xa8) [ 10.992702] [] (handle_irq_event) from [] (handle_fasteoi_irq+0x11c/0x1d4) [ 10.992713] [] (handle_fasteoi_irq) from [] (generic_handle_irq+0x20/0x30) [ 10.992724] [] (generic_handle_irq) from [] (__handle_domain_irq+0x6c/0xe4) [ 10.992734] [] (__handle_domain_irq) from [] (gic_handle_irq+0x2c/0x68) [ 10.992744] [] (gic_handle_irq) from [] (__irq_svc+0x40/0x88) [ 10.992749] Exception stack(0xed889b28 to 0xed889b70) ... ... Signed-off-by: Anders Roxell --- drivers/i2c/busses/i2c-exynos5.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c index b29c750..b12e77e 100644 --- a/drivers/i2c/busses/i2c-exynos5.c +++ b/drivers/i2c/busses/i2c-exynos5.c @@ -170,7 +170,7 @@ struct exynos5_i2c { struct device *dev; int state; - spinlock_t lock; /* IRQ synchronization */ + raw_spinlock_t lock; /* IRQ synchronization */ /* * Since the TRANS_DONE bit is cleared on read, and we may read it @@ -433,7 +433,7 @@ static irqreturn_t exynos5_i2c_irq(int irqno, void *dev_id) i2c->state = -EINVAL; - spin_lock(&i2c->lock); + raw_spin_lock(&i2c->lock); int_status = readl(i2c->regs + HSI2C_INT_STATUS); writel(int_status, i2c->regs + HSI2C_INT_STATUS); @@ -521,7 +521,7 @@ static irqreturn_t exynos5_i2c_irq(int irqno, void *dev_id) complete(&i2c->msg_complete); } - spin_unlock(&i2c->lock); + raw_spin_unlock(&i2c->lock); return IRQ_HANDLED; } @@ -610,7 +610,7 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop) * Enable interrupts before starting the transfer so that we don't * miss any INT_I2C interrupts. */ - spin_lock_irqsave(&i2c->lock, flags); + raw_spin_lock_irqsave(&i2c->lock, flags); writel(int_en, i2c->regs + HSI2C_INT_ENABLE); if (stop == 1) @@ -618,7 +618,7 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop) i2c_auto_conf |= i2c->msg->len; i2c_auto_conf |= HSI2C_MASTER_RUN; writel(i2c_auto_conf, i2c->regs + HSI2C_AUTO_CONF); - spin_unlock_irqrestore(&i2c->lock, flags); + raw_spin_unlock_irqrestore(&i2c->lock, flags); } static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, @@ -763,7 +763,7 @@ static int exynos5_i2c_probe(struct platform_device *pdev) /* Clear pending interrupts from u-boot or misc causes */ exynos5_i2c_clr_pend_irq(i2c); - spin_lock_init(&i2c->lock); + raw_spin_lock_init(&i2c->lock); init_completion(&i2c->msg_complete); i2c->irq = ret = platform_get_irq(pdev, 0);