From patchwork Tue Jun 2 14:00:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 213944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AF7BC433E2 for ; Tue, 2 Jun 2020 14:01:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C76F2074B for ; Tue, 2 Jun 2020 14:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591106490; bh=SFnZGfuUZh9BGwo8gb4PEuJJ3RLFPSIYhTnGuCGCLD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=FfmLgX0PEciN7cismUNeSpl/YijDul09ElMrPGNOLwJFZ9UFOo6pOtU5V8RI/axim NDYOdp15spxVohc/P4CgJCrk10vSYFZtjikHlgHZldM4rfjVYVH16yoGsR1m35Q3tc DWSBgeZhEzUaXx6dMJzOYxsg9VBKYAGG9If+Zcjg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727070AbgFBOB3 (ORCPT ); Tue, 2 Jun 2020 10:01:29 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41445 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbgFBOB3 (ORCPT ); Tue, 2 Jun 2020 10:01:29 -0400 Received: by mail-lf1-f67.google.com with SMTP id u16so6239239lfl.8; Tue, 02 Jun 2020 07:01:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7TsTVRy6VoIywIRL97JtwPjdmIS2xffzmjhoZrIa1AA=; b=eOsGiqaPePBg9gD9SVka1Kwq1CpL2OBOyyPJrYxi5m2hYmtOJ/v7bu83HfKBdkLZWc oj6mSbMP9vdotQC3eXB6t3hrE0VFnA6P//g1hV3p+uiWHy0Y3KoeFX1aITko7+eUlgWq sQSVqU0B/DSxw4QSn1mGUFCRGBHKzxIW0xaUfpnvH7rx3eTMO1tIqDOHi2BYVPlI19jT cr9C4gqu2gWSyPjibVvqIXrXbKzhM5rBDrGTp2Pc1Y8YnlMR444FUbSgmiaDK66jVtka ImfiBBofIpz4ws2gLKmOnyMvXmKMeIkPV6lMH97mLwdUU6XESQ2ycJX2VteAEFV0qvhc s7Og== X-Gm-Message-State: AOAM5332KyAMv1YJFYfNqibUZfQUJ+OvZbEoFt+fRMNExqTNZe05uzKh 1vB1yivc31atZcVGCGxU0TM= X-Google-Smtp-Source: ABdhPJyua9OTdM+nCysSu614tZnmPjAqAmTU6yC4euXIi+HEamZNG2cLy12oe+as8rRKEabuEdEN8g== X-Received: by 2002:ac2:485a:: with SMTP id 26mr13899122lfy.57.1591106486401; Tue, 02 Jun 2020 07:01:26 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id s13sm825849lfp.81.2020.06.02.07.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 07:01:25 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1jg7Ti-0000xz-RD; Tue, 02 Jun 2020 16:01:18 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , Dmitry Safonov <0x7f454c46@gmail.com>, Andy Shevchenko , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 2/4] serial: core: fix broken sysrq port unlock Date: Tue, 2 Jun 2020 16:00:56 +0200 Message-Id: <20200602140058.3656-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602140058.3656-1-johan@kernel.org> References: <20200602140058.3656-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Commit d6e1935819db ("serial: core: Allow processing sysrq at port unlock time") worked around a circular locking dependency by adding helpers used to defer sysrq processing to when the port lock was released. A later commit unfortunately converted these inline helpers to exported functions despite the fact that the unlock helper was restoring irq flags, something which needs to be done in the same function that saved them (e.g. on SPARC). Fixes: 8e20fc391711 ("serial_core: Move sysrq functions from header file") Cc: stable # 5.6 Cc: Dmitry Safonov <0x7f454c46@gmail.com> Signed-off-by: Johan Hovold --- drivers/tty/serial/serial_core.c | 19 ------------------- include/linux/serial_core.h | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index edfb7bc14bbf..f6cf9cc4ce69 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3239,25 +3239,6 @@ int uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch) } EXPORT_SYMBOL_GPL(uart_prepare_sysrq_char); -void uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags) -{ - int sysrq_ch; - - if (!port->has_sysrq) { - spin_unlock_irqrestore(&port->lock, irqflags); - return; - } - - sysrq_ch = port->sysrq_ch; - port->sysrq_ch = 0; - - spin_unlock_irqrestore(&port->lock, irqflags); - - if (sysrq_ch) - handle_sysrq(sysrq_ch); -} -EXPORT_SYMBOL_GPL(uart_unlock_and_check_sysrq); - /* * We do the SysRQ and SAK checking like this... */ diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 1f4443db5474..858c5dd926ad 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -462,8 +462,25 @@ extern void uart_insert_char(struct uart_port *port, unsigned int status, extern int uart_handle_sysrq_char(struct uart_port *port, unsigned int ch); extern int uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch); -extern void uart_unlock_and_check_sysrq(struct uart_port *port, - unsigned long irqflags); + +static inline void uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags) +{ + int sysrq_ch; + + if (!port->has_sysrq) { + spin_unlock_irqrestore(&port->lock, irqflags); + return; + } + + sysrq_ch = port->sysrq_ch; + port->sysrq_ch = 0; + + spin_unlock_irqrestore(&port->lock, irqflags); + + if (sysrq_ch) + handle_sysrq(sysrq_ch); +} + extern int uart_handle_break(struct uart_port *port); /*