Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp871941pxb; Fri, 13 Aug 2021 08:09:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlONEPJt7U7hGqXQw2rrdpai128TVwB1NUzEAkCnEeiv/u0NhgEa+3+22SeoKgXDO2d+ux X-Received: by 2002:a5d:8941:: with SMTP id b1mr2380476iot.45.1628867380269; Fri, 13 Aug 2021 08:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867380; cv=none; d=google.com; s=arc-20160816; b=o+KnXJ/MF9P7MhRAIWr8cX1tHBijgiZiEMLa0GMt0CnzwV7CZSlb8wg2uWhzQ6rDsS yNn2fSvFhlNKRGVT482EFqt7AENKYWUzL3lACoxepl9I3uTmjEygnGNw4xUQFQUhVSrs lV5U7xl+eq/1Bg4KIrWBrAjpd/dS4B/6gWm648pvId57JQWjH0jethm79NRTZqYdoAPi vHYWDwAUaUPJ1kg+adSqcaFL9gqJVbXmiqWteJdsqO/BgepbXgB5Bn0AZwbUvX4IMB/v 4XqpHYJapoweYb46dk+3PY5NGRR03ENtE/UNWC4Bi4kIs2+RzZWlfkXxQHxBvQmOHZt2 Cq3w== 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=mO6+7r+i2WzBqxYrS7GWVuFyfchyqBxoXGG+iNLThaw=; b=wE7k+A2dIq/v8jn5QZE3weiVyUL2j1sTZxxi1P6WqQjTEnQtwXQY8UlL1Gl8DyS8lu oY3daAlmfCE/CAz1PuzwFNREJ6rhnxVIF/HPYKS3VTNHapThyVQbXE3J/tT6PJKeeG+U Q4nd6ui7cT+Qv9g9Aic45ClxXhi8M5ZWoNZAz5gyy5m36QQ1dKlGFwNvMrFXO7y+lX0V R2SsBvV7YRRS40pwR9PDkMDfAHveOMGSUxc16kSiagHeULScr417EYUJLjd+ttEFMoni xRaXuEzRjRFgbNuAhidaJrIWWLsAe4QPPl49HU344VqnuhCbUNuhhRK4nSI2hv9YK6b3 PKYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hTnVQCzG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d7si1736204iop.31.2021.08.13.08.09.28; Fri, 13 Aug 2021 08:09:40 -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=@linuxfoundation.org header.s=korg header.b=hTnVQCzG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241168AbhHMPIo (ORCPT + 99 others); Fri, 13 Aug 2021 11:08:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:50972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241147AbhHMPIk (ORCPT ); Fri, 13 Aug 2021 11:08:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4EA5461106; Fri, 13 Aug 2021 15:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867293; bh=qT9QoGe6vzZYvvq/osf6/mHJJetAvGUoSU0Mo3XpB+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hTnVQCzGTQpGuUNSoOnKdJ+EV8HzFLGv/eDZHIenguS407idEGmd9iWE+aq7Wco7T TwNLdJlDCygg7eidqBX2hck6CmKK6eStpYfdpVFyMSO1mYSkMryAcalUXm71i/Sxt+ hptkmYGGxUZUnhqBukTw8QXIvF+ywITjWArbQIVk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Maciej W. Rozycki" Subject: [PATCH 4.4 15/25] serial: 8250: Mask out floating 16/32-bit bus bits Date: Fri, 13 Aug 2021 17:06:39 +0200 Message-Id: <20210813150521.220281022@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150520.718161915@linuxfoundation.org> References: <20210813150520.718161915@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maciej W. Rozycki commit e5227c51090e165db4b48dcaa300605bfced7014 upstream. Make sure only actual 8 bits of the IIR register are used in determining the port type in `autoconfig'. The `serial_in' port accessor returns the `unsigned int' type, meaning that with UPIO_AU, UPIO_MEM16, UPIO_MEM32, and UPIO_MEM32BE access types more than 8 bits of data are returned, of which the high order bits will often come from bus lines that are left floating in the data phase. For example with the MIPS Malta board's CBUS UART, where the registers are aligned on 8-byte boundaries and which uses 32-bit accesses, data as follows is returned: YAMON> dump -32 0xbf000900 0x40 BF000900: 1F000942 1F000942 1F000900 1F000900 ...B...B........ BF000910: 1F000901 1F000901 1F000900 1F000900 ................ BF000920: 1F000900 1F000900 1F000960 1F000960 ...........`...` BF000930: 1F000900 1F000900 1F0009FF 1F0009FF ................ YAMON> Evidently high-order 24 bits return values previously driven in the address phase (the 3 highest order address bits used with the command above are masked out in the simple virtual address mapping used here and come out at zeros on the external bus), a common scenario with bus lines left floating, due to bus capacitance. Consequently when the value of IIR, mapped at 0x1f000910, is retrieved in `autoconfig', it comes out at 0x1f0009c1 and when it is right-shifted by 6 and then assigned to 8-bit `scratch' variable, the value calculated is 0x27, not one of 0, 1, 2, 3 expected in port type determination. Fix the issue then, by assigning the value returned from `serial_in' to `scratch' first, which masks out 24 high-order bits retrieved, and only then right-shift the resulting 8-bit data quantity, producing the value of 3 in this case, as expected. Fix the same issue in `serial_dl_read'. The problem first appeared with Linux 2.6.9-rc3 which predates our repo history, but the origin could be identified with the old MIPS/Linux repo also at: as commit e0d2356c0777 ("Merge with Linux 2.6.9-rc3."), where code in `serial_in' was updated with this case: + case UPIO_MEM32: + return readl(up->port.membase + offset); + which made it produce results outside the unsigned 8-bit range for the first time, though obviously it is system dependent what actual values appear in the high order bits retrieved and it may well have been zeros in the relevant positions with the system the change originally was intended for. It is at that point that code in `autoconf' should have been updated accordingly, but clearly it was overlooked. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org # v2.6.12+ Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Maciej W. Rozycki Link: https://lore.kernel.org/r/alpine.DEB.2.21.2106260516220.37803@angie.orcam.me.uk Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_port.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -274,7 +274,11 @@ configured less than Maximum supported f /* Uart divisor latch read */ static int default_serial_dl_read(struct uart_8250_port *up) { - return serial_in(up, UART_DLL) | serial_in(up, UART_DLM) << 8; + /* Assign these in pieces to truncate any bits above 7. */ + unsigned char dll = serial_in(up, UART_DLL); + unsigned char dlm = serial_in(up, UART_DLM); + + return dll | dlm << 8; } /* Uart divisor latch write */ @@ -1160,9 +1164,11 @@ static void autoconfig(struct uart_8250_ serial_out(up, UART_LCR, 0); serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); - scratch = serial_in(up, UART_IIR) >> 6; - switch (scratch) { + /* Assign this as it is to truncate any bits above 7. */ + scratch = serial_in(up, UART_IIR); + + switch (scratch >> 6) { case 0: autoconfig_8250(up); break;