Received: by 10.192.165.148 with SMTP id m20csp4049269imm; Tue, 8 May 2018 01:56:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq3/4cSFF+HWeEVOuvCKMfrj/uMSr+ypLCMG0kBsOwko93VyKOiykIF3A8IBG3Zz2b37qeV X-Received: by 2002:a63:9d0c:: with SMTP id i12-v6mr31027715pgd.87.1525769769779; Tue, 08 May 2018 01:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525769769; cv=none; d=google.com; s=arc-20160816; b=uU9uPCZq4c1V2F83AEDRz1a0I6iQ8pfCzwzqhiaawYcpWhMayYWjfovsAlr5JdUFrl jGVvkd91MxVy0ZG6/9bR5rxsOlCjNFWQ0h9I24wo5DfMSCfBOaeKKr+HYyQOgiHMqAAF KNDf9FUb/I95dAqNnKHPtJhYtfsdwMJ9A8QjYqsj1tSb91PejtqnUyVnYUMb90tSP3NG sXIUDqYpsizKZdWxzNVlzb4kU0/BffkQBNBfZ88EGRKvXQfoianpFOqygQ/AeELR/GaI gqRYYo5Kcm1ZoNwN0O6FxY8emobsgsOEc7TV+Y9ajtKHJWTz3A045NdCBj4P27PeT0Sg yPmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Xb8uCgalpYkz2uo7gGPODUBgz8fRsA+uaQaQBDd0dQQ=; b=keSP/IXbPr2KDRCDTRtbV8c0Q2aUx9wLK2cqIL8BLZL7K8HBDdgt/0YxoqneaurYSW bWu8pI5qV3wM+4uqpgJcoizs8K3wa3aq/ht7wM9AjZQ8EtuQehAVGIjCLA+OGcO1F0RU pcY+T4xjvJbT02odwX8CiqVQUbmYDfztsJyAaZWnk43jo6ZBofeE7ZWVMYl6VeANiYAY AT1ZaQvXx+4lgrW/nKsvYszuN0RiAAahiIuu9fCsEZtYGyDJ22wkVrirOI2e2lV1xIqu 7DKCwZBRjxAOE7iyN6ywoBPoDOZ7Q9mVXobW9ZZ/qdw3xCIgq8bvXcuBaul1t+GC93pw 6i+Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=monom.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6-v6si20556427plp.175.2018.05.08.01.55.55; Tue, 08 May 2018 01:56:09 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=monom.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933509AbeEHIzX (ORCPT + 99 others); Tue, 8 May 2018 04:55:23 -0400 Received: from mail.monom.org ([188.138.9.77]:40190 "EHLO mail.monom.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933489AbeEHIzS (ORCPT ); Tue, 8 May 2018 04:55:18 -0400 Received: from mail.monom.org (localhost [127.0.0.1]) by filter.mynetwork.local (Postfix) with ESMTP id D5B66500E05; Tue, 8 May 2018 10:55:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on mail.monom.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 Received: from localhost (ppp-93-104-170-164.dynamic.mnet-online.de [93.104.170.164]) by mail.monom.org (Postfix) with ESMTPSA id 7E7785007F3; Tue, 8 May 2018 10:55:15 +0200 (CEST) From: Daniel Wagner To: linux-kernel@vger.kernel.org Cc: linux-rt-users@vger.kernel.org, linux-serial@vger.kernel.org, linux-sh@vger.kernel.org, gregkh@linuxfoundation.org, Daniel Wagner , Geert Uytterhoeven , Sebastian Andrzej Siewior Subject: [PATCH v3] serial: sh-sci: Use spin_{try}lock_irqsave instead of open coding version Date: Tue, 8 May 2018 10:55:09 +0200 Message-Id: <20180508085509.31384-1-wagi@monom.org> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Wagner Commit 40f70c03e33a ("serial: sh-sci: add locking to console write function to avoid SMP lockup") copied the strategy to avoid locking problems in conjuncture with the console from the UART8250 driver. Instead using directly spin_{try}lock_irqsave(), local_irq_save() followed by spin_{try}lock() was used. While this is correct on mainline, for -rt it is a problem. spin_{try}lock() will check if it is running in a valid context. Since the local_irq_save() has already been executed, the context has changed and spin_{try}lock() will complain. The reason why spin_{try}lock() complains is that on -rt the spin locks are turned into mutexes and therefore can sleep. Sleeping with interrupts disabled is not valid. BUG: sleeping function called from invalid context at /home/wagi/work/rt/v4.4-cip-rt/kernel/locking/rtmutex.c:995 in_atomic(): 0, irqs_disabled(): 128, pid: 778, name: irq/76-eth0 CPU: 0 PID: 778 Comm: irq/76-eth0 Not tainted 4.4.126-test-cip22-rt14-00403-gcd03665c8318 #12 Hardware name: Generic RZ/G1 (Flattened Device Tree) Backtrace: [] (dump_backtrace) from [] (show_stack+0x18/0x1c) r7:c06b01f0 r6:60010193 r5:00000000 r4:c06b01f0 [] (show_stack) from [] (dump_stack+0x78/0x94) [] (dump_stack) from [] (___might_sleep+0x134/0x194) r7:60010113 r6:c06d3559 r5:00000000 r4:ffffe000 [] (___might_sleep) from [] (rt_spin_lock+0x20/0x74) r5:c06f4d60 r4:c06f4d60 [] (rt_spin_lock) from [] (serial_console_write+0x100/0x118) r5:c06f4d60 r4:c06f4d60 [] (serial_console_write) from [] (call_console_drivers.constprop.15+0x10c/0x124) r10:c06d2894 r9:c04e18b0 r8:00000028 r7:00000000 r6:c06d3559 r5:c06d2798 r4:c06b9914 r3:c02576e4 [] (call_console_drivers.constprop.15) from [] (console_unlock+0x32c/0x430) r10:c06d30d8 r9:00000028 r8:c06dd518 r7:00000005 r6:00000000 r5:c06d2798 r4:c06d2798 r3:00000028 [] (console_unlock) from [] (vprintk_emit+0x394/0x4f0) r10:c06d2798 r9:c06d30ee r8:00000006 r7:00000005 r6:c06a78fc r5:00000027 r4:00000003 [] (vprintk_emit) from [] (vprintk+0x28/0x30) r10:c060bd46 r9:00001000 r8:c06b9a90 r7:c06b9a90 r6:c06b994c r5:c06b9a3c r4:c0062fa8 [] (vprintk) from [] (vprintk_default+0x10/0x14) [] (vprintk_default) from [] (printk+0x78/0x84) [] (printk) from [] (credit_entropy_bits+0x17c/0x2cc) r3:00000001 r2:decade60 r1:c061a5ee r0:c061a523 r4:00000006 [] (credit_entropy_bits) from [] (add_interrupt_randomness+0x160/0x178) r10:466e7196 r9:1f536000 r8:fffeef74 r7:00000000 r6:c06b9a60 r5:c06b9a3c r4:dfbcf680 [] (add_interrupt_randomness) from [] (irq_thread+0x1e8/0x248) r10:c006537c r9:c06cdf21 r8:c0064fcc r7:df791c24 r6:df791c00 r5:ffffe000 r4:df525180 [] (irq_thread) from [] (kthread+0x108/0x11c) r10:00000000 r9:00000000 r8:c0065184 r7:df791c00 r6:00000000 r5:df791d00 r4:decac000 [] (kthread) from [] (ret_from_fork+0x14/0x3c) r8:00000000 r7:00000000 r6:00000000 r5:c003fa9c r4:df791d00 Cc: Geert Uytterhoeven Cc: Sebastian Andrzej Siewior Signed-off-by: Daniel Wagner --- changes since v2: - dropped the local_irq_save() it's wrong as Sebastian pointed out changes since v1: - Ported to current mainline (initial version was against v4.4.y) - Left local_irq_save() in place when spinlocks are not used as suggested by Geert. drivers/tty/serial/sh-sci.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index fdbbff547106..8c8dcced1c25 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2890,16 +2890,15 @@ static void serial_console_write(struct console *co, const char *s, unsigned long flags; int locked = 1; - local_irq_save(flags); #if defined(SUPPORT_SYSRQ) if (port->sysrq) locked = 0; else #endif if (oops_in_progress) - locked = spin_trylock(&port->lock); + locked = spin_trylock_irqsave(&port->lock, flags); else - spin_lock(&port->lock); + spin_lock_irqsave(&port->lock, flags); /* first save SCSCR then disable interrupts, keep clock source */ ctrl = serial_port_in(port, SCSCR); @@ -2919,8 +2918,7 @@ static void serial_console_write(struct console *co, const char *s, serial_port_out(port, SCSCR, ctrl); if (locked) - spin_unlock(&port->lock); - local_irq_restore(flags); + spin_unlock_irqrestore(&port->lock, flags); } static int serial_console_setup(struct console *co, char *options) -- 2.14.3