Received: by 10.192.165.148 with SMTP id m20csp2764374imm; Mon, 7 May 2018 00:15:10 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoevsLkb+FRxLvSIWzDIU9AyqXYVSao25TGR2wQhV33VJX0QFYyuO4dMl5py+yzhy3uiVGA X-Received: by 2002:a17:902:8d8b:: with SMTP id v11-v6mr38090294plo.9.1525677310793; Mon, 07 May 2018 00:15:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525677310; cv=none; d=google.com; s=arc-20160816; b=zpEESCQwdMA8Mpg7iWX677rG3GjHHT72XRrcXe6bmPMnh3IzD+5z8uTEWOWd34WjNw xW5LaVotZxJhyDo5BlZOYQ/Yy/WJVZP2Y5N09TrdFRDez8yNvit4D1fJEu3cHUIHlX1P ZpFsgOqwrmX/vJlSgyVyqUtA7HcQlZGzPJh63agh92GrQkFRIjFBg9HgUKMK6d1/0jYk dvmhKOK94rpGla+jxCLZ1JyQoGnCGyIbWdWQp4E/xmDNgs0DbuB0PSBlwSGNkdzAhEPM 5YLnAo8ngC5vN+zyFUnVvOQfRkKd5YWiUrefqtmLQk/GCwinYcaJ0eHGLWOnW7kmNoxS gc1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=fS9j+9cuqgrj+qcukKEJ1ZEq9N/9yMR+aiaQg5jL8R8=; b=q1JB54l+4NeJrqNSJfi8ubWU8LQ7I2xCozchB9o4fxWTVfgF5rvKuaPon7MDgr6HLq tuGnOgtUgfR/E8Sh+Nu1CRUqM1VuTwJKiTQl/Ykfh4iiDLBpTjfcQ9Qalz3/h5Y3n88J sy/sVDgV/0zI41hKANxNJTa6cVSlroPTUGNE8lrXMWnMEvIQWeupoPKiPL7iOG0TFqji AcuxxyJ/+fCFiyPAF03ZECNYwBj9dogKUcB3fFZ8iH9zpI/NgW8e1iFpQcez5ElVYWKi QBrIRRjMRs4saWmbAaAXcXBq45BJfN2pJ7GAd/Cpww0eUVc0FGmtSetvCR34ka5lH4oi KkHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=cjkBs5qE; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14si6341429pfn.41.2018.05.07.00.14.55; Mon, 07 May 2018 00:15:10 -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=fail header.i=@gmail.com header.s=20161025 header.b=cjkBs5qE; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751900AbeEGHOn (ORCPT + 99 others); Mon, 7 May 2018 03:14:43 -0400 Received: from mail-ua0-f194.google.com ([209.85.217.194]:35691 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751010AbeEGHOk (ORCPT ); Mon, 7 May 2018 03:14:40 -0400 Received: by mail-ua0-f194.google.com with SMTP id a2so17275536uak.2; Mon, 07 May 2018 00:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=fS9j+9cuqgrj+qcukKEJ1ZEq9N/9yMR+aiaQg5jL8R8=; b=cjkBs5qEO5oMn80enyc76kgCYSJXv2Phctio1RzNY8hLv/1R/aJxHOWNf6FxcfnUdO gOQou5eiZu7St5joL2yuG7nMsKWeKgS+s9XePwBA2/afYd/Yy6QPPOLkw8tCTp6x34A3 zBMTA5SNR73nW711bzPwPvtb/5ZCO2rh755SFZAnZZKEDSa9WgycNPB7bE4lbhye0EWh xu7y8CYdMghIH/le2A3egNStrdrO3h0rQkUp6IR1ZR5ZZNUGsfSuo9dEEScQIlhQfEyZ +th+n01DNFVymg3Fc8b0wauF9N4PL4F7ZYXESku7xVyEb6ElHX1Q6wmIukHto0Rg7tYN CoSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=fS9j+9cuqgrj+qcukKEJ1ZEq9N/9yMR+aiaQg5jL8R8=; b=XhS7Ji2Rygw/sDlkH7AUrx9QWkCaj6D2K6M/oXB8dF2dRx5kIWOD+OtmFLYolu1tFt MVj787e8KtE+Tj/LayfX16DiBxkTDTYNgfilvlOdtHdmzkZGFK3FlBVHUFGPfsiWSSrP c/qHM7ZQEexPXfx/9dbLA4LvaYD2lWYIblxK2uuHTT4DLfx2pCaLCr+pZG11wbWrfM+B OZgEGhce78o9GKzvx7KBN5Adxo4kwuIvZJ9XSuDmgqZ5WzAPtJziqTe9iFrwrFyLzwBr QNpQbjpppg5LY4g1vPRzLix49XshzBPsw6BzaKmO+ywbUlGgdZQRRNEvI6jmMom0mB9f nqJQ== X-Gm-Message-State: ALQs6tCyadyjbb5aQWb14hwlhTxwl4wutIOd8WydA2mJPBLQQZsuI2wl SYgbnl4JG8LBnFvtASuQvLb0EatveuSM8PdjvBY= X-Received: by 10.176.36.147 with SMTP id i19mr31131156uan.180.1525677279072; Mon, 07 May 2018 00:14:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.122.10 with HTTP; Mon, 7 May 2018 00:14:38 -0700 (PDT) In-Reply-To: <20180504163041.28726-1-wagi@monom.org> References: <20180504163041.28726-1-wagi@monom.org> From: Geert Uytterhoeven Date: Mon, 7 May 2018 09:14:38 +0200 X-Google-Sender-Auth: -gzNzFRi7SJT8eXOzXTasw5Ax6E Message-ID: Subject: Re: [PATCH v2] serial: sh-sci: Use spin_{try}lock_irqsave instead of open coding version To: Daniel Wagner Cc: Linux Kernel Mailing List , linux-rt-users@vger.kernel.org, "open list:SERIAL DRIVERS" , Linux-sh list , Greg KH , Daniel Wagner Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, On Fri, May 4, 2018 at 6:30 PM, Daniel Wagner wrote: > 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. [...] > --- > > 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. Thanks for the update! > --- a/drivers/tty/serial/sh-sci.c > +++ b/drivers/tty/serial/sh-sci.c > @@ -2890,16 +2890,16 @@ 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) > + if (port->sysrq) { > locked = 0; > - else > + local_irq_save(flags); > + } else > #endif > if (oops_in_progress) > - locked = spin_trylock(&port->lock); > + locked = spin_trylock_irqsave(&port->lock, flags); If the spinlock could not be taken, interrupts are re-enabled: include/linux/spinlock.h: #define raw_spin_trylock_irqsave(lock, flags) \ ({ \ local_irq_save(flags); \ raw_spin_trylock(lock) ? \ 1 : ({ local_irq_restore(flags); 0; }); \ }) hence I think you need to check for this and disable interrupts again: if (!locked) local_irq_save(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 +2919,9 @@ 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); > + else > + local_irq_restore(flags); > } > > static int serial_console_setup(struct console *co, char *options) Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds