Received: by 10.192.165.148 with SMTP id m20csp1536480imm; Thu, 3 May 2018 00:44:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq9SG0EayJtGFJWKVi5asg/Fp3TlwYhMJ83GI/XDInedVM6l+Z61XAlITzj1+FY2x4W5GyJ X-Received: by 2002:a63:730c:: with SMTP id o12-v6mr18354989pgc.1.1525333451174; Thu, 03 May 2018 00:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525333451; cv=none; d=google.com; s=arc-20160816; b=aTaZBlCiGgvuX0jrcnIjw8hsm2YL3Rl76LyVo744K08+c+c+cSI1PrlT6y4K7Pufnx l0Kv8kOLA+z0py+qZZZ8Rgh8NnETdL1tqt/IjLkQqDAbDP6gca4YgdtDnFcCYG/rHWbD 1p6UgW5wTEhYqLKsgxPcrH1ihAAlFJn+YyBLF3ShaROx+dCZgdsBBy0z6zhxBN05lB/x DtJ38ov0xGHuhL+fdYJf30+vauQrOs6v1L3ZL4PUqBamaGAGTXp6wyKTrgPe+fnL4lkh ybRCmWXHbkPn5TWCLMENE4+dL2NwoWkrBtV9vi7ySsmEo4hUia9WsfpSOzWMjQ+iUjFl spUw== 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=LuubrRPYOUglDNW4OoVvkAm8ajzbUHey6peXm0Xmn8c=; b=itpX5no9gZLU8C31LsEykerYNWXm0r1Tli3XcL8iW1jEe0ggdT7A+xZ0GhvmGyyN2x hIE30qUNkdh56825BLgY44nZSCEFW++4sdeCvCXOXc0MDJvUjRHZyhdnMZjH7vGdq/Le GssJJwumPcneUyJ3oHNgPg769Cw7hhX6Ul2daYneZRemFvHT2fIsHx9jr66yGpc6H30H tc29pLLoUA+s49oSK0IP6SLniVZzUC7iqYFnskxzP+MSj2n7DFqRSD7Bh9t6zLCye39Q LGKv1L8ZfXMwQ8Wl0Sc2bTGc5yUJnJ/8OKYRDrX1jp7KwMpn89VKJk96uegZHfe11evD 5giA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=vbGkxdQC; 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 d17-v6si2182714pll.590.2018.05.03.00.43.56; Thu, 03 May 2018 00:44:11 -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=vbGkxdQC; 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 S1751261AbeECHnl (ORCPT + 99 others); Thu, 3 May 2018 03:43:41 -0400 Received: from mail-ua0-f196.google.com ([209.85.217.196]:39127 "EHLO mail-ua0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751043AbeECHnf (ORCPT ); Thu, 3 May 2018 03:43:35 -0400 Received: by mail-ua0-f196.google.com with SMTP id v17so1898834uak.6; Thu, 03 May 2018 00:43:34 -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=LuubrRPYOUglDNW4OoVvkAm8ajzbUHey6peXm0Xmn8c=; b=vbGkxdQCVp0hG2+luvJBdkt3jL/Kq/4rG6tucN4ziEsRGId7jlyNXtPrxOnY3w3yza BnDjYLRIBSQtI+KVaHDMs7n/ZmGTBSdccFlgrIK81DhMTsePIO0VMGhJpu+zcw5vNVkK MgZqLw9Vcq3fTPJtZz3pcqtu8ltFHs4UZBbhU5mtNBbt7RSGv27mnzPb0bDUUeZ5gKdm VWlKYgjjEPN/e15Z8zhjo00nJv2SEvqHZAe50KlDzZd8ZBRju57g/uZ/129NxselbWyS fmzMKGT8SGLrxA/kW6Qv5uGp+rjiX37XlMREN+4ff6iHbeyp/HFlw32SSpVijBhDPOZZ IhpQ== 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=LuubrRPYOUglDNW4OoVvkAm8ajzbUHey6peXm0Xmn8c=; b=AktW6sXRjIqhio7yz92Z8rPcVoClsWukk1EhSzHwjeJxLITQyL2oWWq9b/M5Fzh0+Z 1XHP048lW9tbO6hqtlDp/6bwuedyUt1w+vl6IWwsxlNujcPOkdNUdH9tRslMqQsPGhku 9iS1E4n82CiHcTsiP4aHDioZltJ8Nkasfpvs2SBjTtmKG0RsNzeAhzG3A53FCb3oEm4d 5r6x76cEI8emD1Bbj2Jn6RXc/lYBSCacZXJAte2mNBGDHnuih0g6qRUbtc3kMCYCZgs+ VpdRpZod0t3ALdEsf3D1zauZun/B7Q4h3jmowM/ZvLrEtCE5ktUopWtUFePCHorrpuRB CpPw== X-Gm-Message-State: ALQs6tB4pEG3ggDZF8f2BYGwfJ7NfF087vUyJDn92F/9EQ/TFQaZ8Xr3 dcq0f/9wBoSUWR2A2bIK1qy43k8TL2TK2nQmOk8= X-Received: by 10.159.46.15 with SMTP id t15mr22174111uaj.114.1525333414064; Thu, 03 May 2018 00:43:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.122.10 with HTTP; Thu, 3 May 2018 00:43:33 -0700 (PDT) In-Reply-To: <20180430080918.16763-1-wagi@monom.org> References: <20180430080918.16763-1-wagi@monom.org> From: Geert Uytterhoeven Date: Thu, 3 May 2018 09:43:33 +0200 X-Google-Sender-Auth: LUOjtNttwPK4FYDKoOaaUFQCFNk Message-ID: Subject: Re: [PATCH] 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" , Greg Kroah-Hartman , Linux-sh list , Daniel Wagner , Shinya Kuribayashi 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 Mon, Apr 30, 2018 at 10:09 AM, 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. > Cc: Shinya Kuribayashi > Signed-off-by: Daniel Wagner Thanks for your patch! > --- a/drivers/tty/serial/sh-sci.c > +++ b/drivers/tty/serial/sh-sci.c > @@ -2516,13 +2516,12 @@ static void serial_console_write(struct console *co, const char *s, > unsigned long flags; > int locked = 1; > > - local_irq_save(flags); Hence the below now runs with local interrupts enabled. For checking port->sysrq or oops_in_progress that probably isn't an issue. If oops_in_progress is set, you have other problems, and the race condition between checking the flag and calling spin_lock{,_irqsave}() existed before, and is hard to avoid. For actual console printing, I think you want to keep interrupts disabled. > if (port->sysrq) > locked = 0; > else 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); Add if (!locked local_irq_save(flags) here? > /* first save the SCSCR then disable the interrupts */ > ctrl = serial_port_in(port, SCSCR); > @@ -2539,8 +2538,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); else local_irq_restore(flags); > } 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