Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4880254pjb; Mon, 27 Jul 2020 07:28:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpbfFB4cJGT4y3QPocrp5KYoC/UDR6vv/+XBpTT9nZLd2f8GcjQ2DOZV96dp8ja9ceBAH5 X-Received: by 2002:a17:906:d78c:: with SMTP id pj12mr8541894ejb.179.1595860121875; Mon, 27 Jul 2020 07:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860121; cv=none; d=google.com; s=arc-20160816; b=DNAq1Bee2N9U3BRiwWGpiTAmywjArGg7MMzbP8vsVqs+/F3M+0Id52XlP8IJ7hVIHW EeROyKi8XNCm7YX0K2j1l99+iaNAfoAq4bG3aRLi/rs77JQDGlhzIx1lOn3JbEpq3QWp Nh3BWsx7ljz0MzALVRcb6v2LYW0ThnDAccSU+QW29Jal2O9bXov8Q89NdinFXD+DvvYv PDZWT9d94QmhOGO7EO4n6+kv8pHnDhZgXNT+UOed/EjtxsiFJ0uiW2E+i8TEe+BAmODj mXIa2z4PR3PJnRVWsy436PcRP2DsEDxGBznqfD8kTFLrJ7d4q9OCKpvPhluxdsP35Zhs 4AgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HIYnuYp693YTII29kgzYMnXPPvnFxjND9X1+f2+bJ44=; b=dMNx3XIzbYwh4WovjMgxTwoCvvRbyhfZPIQ67w1HIG66SSpDAu3wdsMhj/YmVuaG5C g9wUYN0zvHoY9Lxx/B2pXp88ZdbA0utlqQ6DWb6U4iGmQMR8tag7ZNVtjM57DH37PmLf AQu/7bm6HLZQQZIURQuZ962zJ4MlM0XLG3ujf32zXUg+O081xadudXqZzAz6uubObbOI aaywzHtjOFqpaDU8RM9S8NHkCHylcqgB8eufSqAztBr4iSwfx3w+nHHB6HqdGji5Pfe3 HcOt7LicCXhb5uJI4CTXEclBI1+xwkYc3DhyxzMhNSEKB0DzzQtbzyusMhHdJEAL8yb0 C2KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=veIWri0M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si5404816ejk.740.2020.07.27.07.28.19; Mon, 27 Jul 2020 07:28:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=veIWri0M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732354AbgG0OZB (ORCPT + 99 others); Mon, 27 Jul 2020 10:25:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:54642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732337AbgG0OYz (ORCPT ); Mon, 27 Jul 2020 10:24:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6936F208E4; Mon, 27 Jul 2020 14:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859894; bh=9IPoUjIl9rYUQoHwrqTKJT7UCqyqqU4r75Elw+Qpxr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=veIWri0MyObFTt9IfVdo6PFq2pwYN89p2y4plQ2RMTI9d7MDdwBNvAuMkTeLY5IwS 6lFzvt2xLMbHodjU5PQhZwvONa2HyWRWk7PdH7ws1ltYHXoOJkz2csnKmqetx44TR8 hjmfE4QoJOfUWIbJmmHupo2bVn5xwza2nxVOVdug= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shubhrajyoti Datta , Jan Kiszka , Helmut Grohne Subject: [PATCH 5.7 145/179] tty: xilinx_uartps: Really fix id assignment Date: Mon, 27 Jul 2020 16:05:20 +0200 Message-Id: <20200727134939.735741726@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Helmut Grohne commit 22a82fa7d6c3e16d56a036b1fa697a39b954adf0 upstream. The problems started with the revert (18cc7ac8a28e28). The cdns_uart_console.index is statically assigned -1. When the port is registered, Linux assigns consecutive numbers to it. It turned out that when using ttyPS1 as console, the index is not updated as we are reusing the same cdns_uart_console instance for multiple ports. When registering ttyPS0, it gets updated from -1 to 0, but when registering ttyPS1, it already is 0 and not updated. That led to 2ae11c46d5fdc4. It assigns the index prior to registering the uart_driver once. Unfortunately, that ended up breaking the situation where the probe order does not match the id order. When using the same device tree for both uboot and linux, it is important that the serial0 alias points to the console. So some boards reverse those aliases. This was reported by Jan Kiszka. The proposed fix was reverting the index assignment and going back to the previous iteration. However such a reversed assignement (serial0 -> uart1, serial1 -> uart0) was already partially broken by the revert (18cc7ac8a28e28). While the ttyPS device works, the kmsg connection is already broken and kernel messages go missing. Reverting the id assignment does not fix this. >From the xilinx_uartps driver pov (after reverting the refactoring commits), there can be only one console. This manifests in static variables console_pprt and cdns_uart_console. These variables are not properly linked and can go out of sync. The cdns_uart_console.index is important for uart_add_one_port. We call that function for each port - one of which hopefully is the console. If it isn't, the CON_ENABLED flag is not set and console_port is cleared. The next cdns_uart_probe call then tries to register the next port using that same cdns_uart_console. It is important that console_port and cdns_uart_console (and its index in particular) stay in sync. The index assignment implemented by Shubhrajyoti Datta is correct in principle. It just may have to happen a second time if the first cdns_uart_probe call didn't encounter the console device. And we shouldn't change the index once the console uart is registered. Reported-by: Shubhrajyoti Datta Reported-by: Jan Kiszka Link: https://lore.kernel.org/linux-serial/f4092727-d8f5-5f91-2c9f-76643aace993@siemens.com/ Fixes: 18cc7ac8a28e28 ("Revert "serial: uartps: Register own uart console and driver structures"") Fixes: 2ae11c46d5fdc4 ("tty: xilinx_uartps: Fix missing id assignment to the console") Fixes: 76ed2e10579671 ("Revert "tty: xilinx_uartps: Fix missing id assignment to the console"") Signed-off-by: Helmut Grohne Cc: stable Link: https://lore.kernel.org/r/20200713073227.GA3805@laureti-dev Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/xilinx_uartps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1574,8 +1574,10 @@ static int cdns_uart_probe(struct platfo * If register_console() don't assign value, then console_port pointer * is cleanup. */ - if (!console_port) + if (!console_port) { + cdns_uart_console.index = id; console_port = port; + } #endif rc = uart_add_one_port(&cdns_uart_uart_driver, port); @@ -1588,8 +1590,10 @@ static int cdns_uart_probe(struct platfo #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE /* This is not port which is used for console that's why clean it up */ if (console_port == port && - !(cdns_uart_uart_driver.cons->flags & CON_ENABLED)) + !(cdns_uart_uart_driver.cons->flags & CON_ENABLED)) { console_port = NULL; + cdns_uart_console.index = -1; + } #endif cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node,