Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4471130imw; Tue, 19 Jul 2022 07:14:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbcIpxzq+zPN1QVGE9ngxaobnDDlbMWIs5PX6ftzNGTm+/jlo7S2zUWxUXaXqYJjA003Tz X-Received: by 2002:a05:6808:210f:b0:33a:7640:d742 with SMTP id r15-20020a056808210f00b0033a7640d742mr5324171oiw.71.1658240051248; Tue, 19 Jul 2022 07:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658240051; cv=none; d=google.com; s=arc-20160816; b=PirpU7bXtQqE8qJk2HnrNkBBZrOrO5QheAUCeIH9e2yo/AC1I316ga08nVWy6ay27a iObzinO1Jc5fBM52gQ2C+YtjhWrzQPjmKTcGEOnd7NZl3i0KqfI3ndKjJ/sjvhIjB3zS 0BwiwzpqLdn5h6T5ZpbDov9UAKd+agc/EPjl3N0ekbSKCJmJxKrLhSBMqN3mzVwR6oGo 8KpT6GgvWpEOJrP5XT5X4k1L4jNRgA9/iaZhJ8fiOIPc6tF8T+SjH9GLoNTf0ovz2ECJ atVFLuajDBn2h9ao9HQtfBxKU29aSflGM72zkJ05rKyDo0VVFoKLdCsKiENBkqd2NaSv 1lkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FGG2jrXxpDj0PcKy8ua6GNCCX9ksWqE5KHWCrEy4ZrI=; b=1KoMrT1gn29F0G0lkfC/IAU0520C1iyxhQoV5eG696z8GuXvEuF+KztvPkA9Ob8R2W oi3ZdZF0JmZYRDxfwBZ80/ILDEDNelBsDoRz3mbygASXXeyv8qumOj03cXk35zpGh92F /W9jMnC/p5V/ytj2bcWvGtrR7LnC1wQDKgEpCD7fltN/8uA2/45BL1ESrMCXTi1fAaxa MZQEekuRI+Gd3AQR2HqRUqpCRCYg8ai5K/WfVLPp3UhCHTRnfKyJ88VDjK57Oi/406Re ERF03d3ijZjgPQer7ghPNqGWCEsue8msYhHInyX8zSEdcY2C+Rse5mTyTbxzE6Q9Ldpl i9GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Up76I3z+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a056870c34e00b0010c0712faf0si2381712oak.5.2022.07.19.07.13.57; Tue, 19 Jul 2022 07:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Up76I3z+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243437AbiGSNMS (ORCPT + 99 others); Tue, 19 Jul 2022 09:12:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243221AbiGSNLL (ORCPT ); Tue, 19 Jul 2022 09:11:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABC0F8C3C6; Tue, 19 Jul 2022 05:29:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 36693B81B21; Tue, 19 Jul 2022 12:29:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81C47C341C6; Tue, 19 Jul 2022 12:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658233754; bh=CRJRpp6HYI9IZVUxtigR245gvKwT9UDBJ2BGUwD1Fu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Up76I3z+7TprA6CuxM+bMW5Eex4vNMZPtS2DJXAErR224tynlOztBx2mf8eqejXQd a3jhKAYT5vkbKgtSK9VdkOw09Rr+3Q+H1pj4b7Pid6L03r66AyiV9Kc2vauRZUPwmo Zt+9wf8oBLRxuv3Y44wiz9cOrJ5H7lzLJuf7JXCI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable , Tony Lindgren , Andy Shevchenko , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 5.18 229/231] serial: 8250: Fix PM usage_count for console handover Date: Tue, 19 Jul 2022 13:55:14 +0200 Message-Id: <20220719114732.899303572@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114714.247441733@linuxfoundation.org> References: <20220719114714.247441733@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilpo Järvinen commit f9b11229b79c0fb2100b5bb4628a101b1d37fbf6 upstream. When console is enabled, univ8250_console_setup() calls serial8250_console_setup() before .dev is set to uart_port. Therefore, it will not call pm_runtime_get_sync(). Later, when the actual driver is going to take over univ8250_console_exit() is called. As .dev is already set, serial8250_console_exit() makes pm_runtime_put_sync() call with usage count being zero triggering PM usage count warning (extra debug for univ8250_console_setup(), univ8250_console_exit(), and serial8250_register_ports()): [ 0.068987] univ8250_console_setup ttyS0 nodev [ 0.499670] printk: console [ttyS0] enabled [ 0.717955] printk: console [ttyS0] printing thread started [ 1.960163] serial8250_register_ports assigned dev for ttyS0 [ 1.976830] printk: console [ttyS0] disabled [ 1.976888] printk: console [ttyS0] printing thread stopped [ 1.977073] univ8250_console_exit ttyS0 usage:0 [ 1.977075] serial8250 serial8250: Runtime PM usage count underflow! [ 1.977429] dw-apb-uart.6: ttyS0 at MMIO 0x4010006000 (irq = 33, base_baud = 115200) is a 16550A [ 1.977812] univ8250_console_setup ttyS0 usage:2 [ 1.978167] printk: console [ttyS0] printing thread started [ 1.978203] printk: console [ttyS0] enabled To fix the issue, call pm_runtime_get_sync() in serial8250_register_ports() as soon as .dev is set for an uart_port if it has console enabled. This problem became apparent only recently because 82586a721595 ("PM: runtime: Avoid device usage count underflows") added the warning printout. I confirmed this problem also occurs with v5.18 (w/o the warning printout, obviously). Fixes: bedb404e91bb ("serial: 8250_port: Don't use power management for kernel console") Cc: stable Tested-by: Tony Lindgren Reviewed-by: Andy Shevchenko Reviewed-by: Tony Lindgren Signed-off-by: Ilpo Järvinen Link: https://lore.kernel.org/r/b4f428e9-491f-daf2-2232-819928dc276e@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_core.c | 4 ++++ drivers/tty/serial/serial_core.c | 5 ----- include/linux/serial_core.h | 5 +++++ 3 files changed, 9 insertions(+), 5 deletions(-) --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -560,6 +561,9 @@ serial8250_register_ports(struct uart_dr up->port.dev = dev; + if (uart_console_enabled(&up->port)) + pm_runtime_get_sync(up->port.dev); + serial8250_apply_quirks(up); uart_add_one_port(drv, &up->port); } --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1904,11 +1904,6 @@ static int uart_proc_show(struct seq_fil } #endif -static inline bool uart_console_enabled(struct uart_port *port) -{ - return uart_console(port) && (port->cons->flags & CON_ENABLED); -} - static void uart_port_spin_lock_init(struct uart_port *port) { spin_lock_init(&port->lock); --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -388,6 +388,11 @@ static const bool earlycon_acpi_spcr_ena static inline int setup_earlycon(char *buf) { return 0; } #endif +static inline bool uart_console_enabled(struct uart_port *port) +{ + return uart_console(port) && (port->cons->flags & CON_ENABLED); +} + struct uart_port *uart_get_console(struct uart_port *ports, int nr, struct console *c); int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr,