Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4373866imw; Tue, 19 Jul 2022 05:34:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sIxMYDrvKYb61kjvI4rcXoYdhd4Ub50uQ+psxmjepBbM5PjQ0CjpCgpHp7COalzoKN4Qc+ X-Received: by 2002:a05:6402:294f:b0:43a:ba61:18ed with SMTP id ed15-20020a056402294f00b0043aba6118edmr44223492edb.180.1658234084285; Tue, 19 Jul 2022 05:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658234084; cv=none; d=google.com; s=arc-20160816; b=BJm7u3e1u+c1yjem4a3lgPkoBvWMm/PC8Qc3WggnoEUrGvotSqNkv/VuJaLVpLY4D5 A4+/ox6gDZdidn2ZYs2iqGS+nxikh6JwC+SbDVK/Dz8oqv5kzABasZAOm1+6Vy4BiM1D F9Sj+Jj9uvIbEt6JUPl4KZJlRAzML99Tuc8WbeaFJd88/SFoznQMxsUvAJ6pI0lb8QIk FDxCqcIB3db3OlHUzW2e5rI/uHuRhyr5CLhCT97PiHoXfmSxRlsgPc4zcekD+up6DvZw T1jgXFet0eoKQ1V3T3UMHD0Q8XBbbtnuscP4jlOf4JQ6LYhx9x5V+IbJUzbWFMm6uCJi nTxA== 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=nsoXt+Z/E7JhEJRyr5nvMPJvhXFwiGwbEcvFW0EHMFg=; b=AQNlPiXvv2cAhUJQbighYnWZScijHRcJuoBeUkScbhm+HqeXHBVXsT3AeWctqoBaeP 42p8s1N0xY+2nEQU5xr6BJP0RwWL8JGyiUfOU8nyQV066YvoI6DlSDBW5EHPNX0z7+eT g5mzyC2/Yk9vW1PSqS9bzuNAdmk0Y7qVbiqOqF0DlJKfhT7liWS68usbPCtZIIYit06z d9dUjjeJBM+YulUaIdRQU2OwTYlhAMZUwl0rc1Ih7s/eADoQWH74nrZcsOtaZI+12vGP yVbjpaDBNPshyPzDpxknADrwxaFAncdlxsDuXo/7IobXcG5w6vJRy40Ap7fkzRHobZQx KjVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1z6n6kMA; 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 t12-20020aa7d4cc000000b0043ad1d1d68asi16680721edr.335.2022.07.19.05.34.17; Tue, 19 Jul 2022 05:34:44 -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=1z6n6kMA; 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 S240090AbiGSM1T (ORCPT + 99 others); Tue, 19 Jul 2022 08:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239734AbiGSMZb (ORCPT ); Tue, 19 Jul 2022 08:25:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80FEE509F4; Tue, 19 Jul 2022 05:09:56 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 06A6D615F4; Tue, 19 Jul 2022 12:09:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE3A3C341C6; Tue, 19 Jul 2022 12:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232593; bh=E8+69TaZ2IM2aWfcdtetfdC5ymtkGiNUfdOUYrUlMMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1z6n6kMAePRA8N987EF1PVxgOF0IJqvD+mBjjBZjvI2lEGATkCfAnS7Bbco5Em3Fs VElIZv8bQBHH7zyCcmt+bcZTSOBubOltX5UB+NQQC++q6+57WzBzli8m0srwFEwGPq Cb+KBz1xciJPTqSI2UMUt3X/oulOOqaHy2mR9o0I= 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.10 111/112] serial: 8250: Fix PM usage_count for console handover Date: Tue, 19 Jul 2022 13:54:44 +0200 Message-Id: <20220719114638.023993965@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@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 @@ -571,6 +572,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 @@ -1941,11 +1941,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 @@ -394,6 +394,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,