Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp724364rwd; Thu, 25 May 2023 03:04:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5naKRsxXNVCFMmdXNSO6Irh2d4IjqQSF6jibIIdixH2MeFiJneN/rHvDeNc5PFcP6Gpb0R X-Received: by 2002:a05:6a00:2488:b0:643:980:65b with SMTP id c8-20020a056a00248800b006430980065bmr8585958pfv.2.1685009065619; Thu, 25 May 2023 03:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685009065; cv=none; d=google.com; s=arc-20160816; b=prTEn/ZllVusVY/VUa/IQmDPghAvF/5Ycj0fRct2UWVK7Ma9zxvHbCyFbPwTdduARI j2UesYKcwQn7dCVAXZCuJuvdD2MCicZxfGSVNqPNZQYnZTgZo///U+St3VQWTr7z2KZM bsMQQ8LCLohzhxNa+0mmnfud+v8LZFB7vvho5ExsxQ52QpWeFc+HR39P0iBOvZvWsBgy TQ2Ez73EujjCXCwoGjBDP5Z6DV0W/smpeTNhlsrF6SfTGgA11q16/pQNNgZpgnPuagAL NNkXT45T1JjFrma2xO1QIrsZlNyv3CQKo0x87sBEG/GMtLp4z6tZgD6vHgBzrGdnkTLF SC1Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=nPDJHm4lU4uW5PYPRilpSR3PUXlYNGeyc1k5gm2WMrg=; b=DWRCnBMRT00T+9fmnpkda3A/Vv0pUh5FUT2oJ7LEeMtiHEtiA4VNcX2yLyELj3JvBG jLmpgPHD00sfi52/efTv1tGahwUhLzrzEeqyZ0wuIyEZViRIJRT1QDf6mSyLNsJxQAW7 R2rEz60II0+wxxiXq5/auzKFdquBSSQhAeasc7QOW3mmxxwG0VIaeBd2si6xVIiZLD2s iQIdSSqPH+BH/eVbPrLxUmLn18SY5cFONmyVnjXJngvl3sdKLY6YJp2GrQMJJSYp7xlu DW1d3mbvry8iRWO8ayZjnLHwrWI5YUILbVgDtxYzM97fLEECpnFF6f71NuKy9dmkfBnR 64kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Bn9RR6tF; dkim=neutral (no key) header.i=@linutronix.de header.b=D7c8sfO9; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k123-20020a628481000000b0064d675fc97csi1177391pfd.27.2023.05.25.03.04.12; Thu, 25 May 2023 03:04:25 -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=@linutronix.de header.s=2020 header.b=Bn9RR6tF; dkim=neutral (no key) header.i=@linutronix.de header.b=D7c8sfO9; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240724AbjEYJfO (ORCPT + 99 others); Thu, 25 May 2023 05:35:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240627AbjEYJel (ORCPT ); Thu, 25 May 2023 05:34:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 074271B1; Thu, 25 May 2023 02:34:33 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685007270; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nPDJHm4lU4uW5PYPRilpSR3PUXlYNGeyc1k5gm2WMrg=; b=Bn9RR6tFw4VHxMRtNu5ITPrZWhJi9VsTk3Ief2f7HcBlEtLMBnVNouWr0IM4OCsP02Dq7Q gdWxPPKFD6kokGHfylzCLf1elFujWvrjGvnJqujbqfHuADfuMLyd6ENik68sarNNrhQFuE c4RkxSMLo7Jg4Ctn+oJapV4snGobAEx0h5zm/6LKkgV48KMBlXtUQ7u4cf07BFSCaEYVjs CLVHT/h0C+zTSycU3IFxqCaSwRZY02Qgl4LpRpu15aLv5QBON8m6QA+BXf3T7MUmdcMh/v tARTQSo+S9rmvPFdJm8rCofDsynBzdEdXV+R9vlJp9w5Fe5d9Bc6DCZitRM3iw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685007270; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nPDJHm4lU4uW5PYPRilpSR3PUXlYNGeyc1k5gm2WMrg=; b=D7c8sfO9B0xWafdKccZQxoeJ+NYAiCmP6zJoGfo+FNhKFSWjUhH4xcqrDjjtHasOyuCFUa o6+70hF7B7N+QMDA== To: Greg Kroah-Hartman Cc: Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Jiri Slaby , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Tony Lindgren , Lukas Wunner , Matthias Schiffer , linux-serial@vger.kernel.org Subject: [PATCH tty v1 6/8] serial: 8250: lock port for omap8250_restore_regs() Date: Thu, 25 May 2023 11:37:57 +0206 Message-Id: <20230525093159.223817-7-john.ogness@linutronix.de> In-Reply-To: <20230525093159.223817-1-john.ogness@linutronix.de> References: <20230525093159.223817-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 omap8250_restore_regs() accesses UART_IER. This register is modified twice by each console write (serial8250_console_write()) under the port lock. However, not all calls to omap8250_restore_regs() are under the port lock. Add the missing port locking around omap8250_restore_regs() calls. Add lockdep notation to the omap8250_restore_regs(). Note that this is not fixing a real problem because the serial devices are resumed before console printing is enabled. However, adding this locking allows for clean locking semantics for omap8250_restore_regs() so that lockdep can be used to identify possible problems in the future. It also simplifies synchronization of UART_IER in general by not needing to rely on such implementation details. Signed-off-by: John Ogness --- drivers/tty/serial/8250/8250_omap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c index 3cb9cfa62331..34939462fd69 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -309,6 +309,9 @@ static void omap8250_restore_regs(struct uart_8250_port *up) struct uart_8250_dma *dma = up->dma; u8 mcr = serial8250_in_MCR(up); + /* Port locked to synchronize UART_IER access against the console. */ + lockdep_assert_held_once(&up->port.lock); + if (dma && dma->tx_running) { /* * TCSANOW requests the change to occur immediately however if @@ -1739,8 +1742,11 @@ static int omap8250_runtime_resume(struct device *dev) if (priv->line >= 0) up = serial8250_get_port(priv->line); - if (up && omap8250_lost_context(up)) + if (up && omap8250_lost_context(up)) { + spin_lock_irq(&up->port.lock); omap8250_restore_regs(up); + spin_unlock_irq(&up->port.lock); + } if (up && up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2)) { spin_lock_irq(&up->port.lock); -- 2.30.2