Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3477215ybt; Tue, 30 Jun 2020 03:56:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaimt96QIJ30sdQpqAUfZlaekhst/8gal37Pt6zlQI7P4xmMRbHWEZfm0iwVE34ouyGKOh X-Received: by 2002:a50:934e:: with SMTP id n14mr22412957eda.88.1593514568979; Tue, 30 Jun 2020 03:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593514568; cv=none; d=google.com; s=arc-20160816; b=kcS4a83w9jxsALmk2ZuJR5SucYHbyLxKlIo4uUjMIWwWx3Cjbb9TaLNdKD5hym/vCo f9GEyQ/3VVMURIxa9wzX5k+FDxu4+xyC1cxJT4xnvJpquNn62DlkzhSZMuQUrVVyd2bM BzvkB3inV5IOnPLx1b8gWgXFLlqRiLEkQI4y3BQKrbaLEA7aFctARrcJjNNRmArVbiHb ImgYc1UHN6541QMvkHBA7SkL/4rP2NH5NjvzgRJRdOWUsyTBVIVVeno/7verYtVUDgut RPdx2nwVu9sptTyO5XBRfJC5Db35GyD7pdJ2sdicL0lUnrcWNL95KB420tbsbH8OIMvz kbaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=yXnWMxu3fBL1VWpPWUGZnbKsrn0ARe4p9+UVSrgyfY4=; b=YloSyfSbrWtwXXXirMqgNLE2kJI90d6RnNJgZjYCya6Mvk5A22lMXAuiJbT2Ie3nAO 1csF26sDEDX8vBcC/ldOKjCRlnOH/C+36DeLekSn8+9vdr/TJ7Ts6aK3uwBR/oS/O2Il sbXiFiaewM/kJJRCXSlJg8Zef1Kzn8fwdZTgZ8rzPvYAxWtxs1LPJeFKIf1UlpO55i44 OtJGTK9ug5YLiyQF1qf5uenFY0sHMAmWOa56hRZYptqGoMxXFtf29fz8MrTwMBRRw0P+ elMCwivPURjRVwcmXyRAfzYpY/MZg+raZgUZQ/fSucMz9Qjo8jWd0y+HTv94S02rxUKQ 4SBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vh3PFwH7; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si1547123ejv.375.2020.06.30.03.55.46; Tue, 30 Jun 2020 03:56:08 -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=@gmail.com header.s=20161025 header.b=vh3PFwH7; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732689AbgF3KzR (ORCPT + 99 others); Tue, 30 Jun 2020 06:55:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732591AbgF3KzQ (ORCPT ); Tue, 30 Jun 2020 06:55:16 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A2C5C061755 for ; Tue, 30 Jun 2020 03:55:16 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id cm21so6012pjb.3 for ; Tue, 30 Jun 2020 03:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=yXnWMxu3fBL1VWpPWUGZnbKsrn0ARe4p9+UVSrgyfY4=; b=vh3PFwH7OSmUmtaKe75aA33YtX+8ch/+HDJzhzew5U0rRSKZplqUNrNS1PIQvXPu3u 3oPLI7OLOq7oNkIXDzLc6ggd8qV3BRTyKHFaKF7eo1P+ZkgAGpbii9cWRzqGf5VXWcf1 NeKQbaT3FFvDr/Hpb+JL2tx9FbqoPfoU5wfR5oMTxFT/O/elpp+jUpdcMst8iK8gujXH RJyjzitiuQ+/z0HhZ8dRWUwMZw8HlIS5jfO0GkAbqUPErRRHzVoGnKiC6Xx9eXcbCN/0 uBIm4ZP6cgM0AS3HDN+kDLB36mJi4rfmsFiTeChyRY/oKcmqygOHUyQjBfGFdhtfud8n ZXPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=yXnWMxu3fBL1VWpPWUGZnbKsrn0ARe4p9+UVSrgyfY4=; b=qOHsP7nY/fYM0s3e5aHuy3ehsNuGqiXq5itYrlZCvAdEh5FJuYWS8M+CeasIS2pQG2 x5RxwcEZtbINSNBF1inkLAhjMAlp2+RGTnDNY97u4qRacb1H2W50o7oXR4ySFaQYIgH1 pRfswly9Cz57V4iM7saJUsUCEFW5Okrlov03UIj3vSGNDvBrJJPgetWZB4dYHJptrVs4 ONGkK6NdWuRgd/6EK/1MytxoWtlK2B0wAhsh4hKGKLLa24CyEVV3zVAefgbQGka0QS7z EI0WyS9oY9jW93XmYECnAETaKzhvnF8Qo3Lgc6dDgm+1WcGdECe78/Akxoc7cygDbn1f +WNg== X-Gm-Message-State: AOAM5303K41uCnmA30kxqgPIo3I6HQwBIifsLXkx3c2HX8cJOVy5057k QvueBWBiMCWRO2eBUMHPvIA= X-Received: by 2002:a17:90a:4d87:: with SMTP id m7mr20343508pjh.26.1593514515863; Tue, 30 Jun 2020 03:55:15 -0700 (PDT) Received: from localhost ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id i196sm2428213pgc.55.2020.06.30.03.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 03:55:15 -0700 (PDT) From: Sergey Senozhatsky X-Google-Original-From: Sergey Senozhatsky Date: Tue, 30 Jun 2020 19:55:12 +0900 To: Petr Mladek Cc: Sergey Senozhatsky , Andy Shevchenko , Raul Rangel , Tony Lindgren , Sergey Senozhatsky , linux-kernel , Greg Kroah-Hartman , Andy Shevchenko , kurt@linutronix.de, "S, Shirish" , Peter Zijlstra , John Ogness , Steven Rostedt Subject: Re: UART/TTY console deadlock Message-ID: <20200630105512.GA530@jagdpanzerIV.localdomain> References: <20200630035816.GA21591@jagdpanzerIV.localdomain> <20200630102141.GA11587@alley> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200630102141.GA11587@alley> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (20/06/30 12:21), Petr Mladek wrote: > > So... Do we need to hold uart->port when we disable port->irq? What do we > > race with? Module removal? The function bumps device PM counter (albeit > > for UART_CAP_RPM ports only). > > Honestly, I do not see where a PM counter gets incremented. serial8250_do_startup() serial8250_rpm_get() pm_runtime_get_sync(p->port.dev) But this does not happen for all ports, just for UART_CAP_RPM ones. > Anyway, __disable_irq_nosync() does nothing when > irq_get_desc_buslock() returns NULL. And irq_get_desc_buslock() > takes desc->lock when desc exist. This should be enough to > synchronize any calls. > > > But, at the same time, we do a whole bunch > > of unprotected port->FOO accesses in serial8250_do_startup(). We even set > > the IRQF_SHARED up->port.irqflags without grabbing the port->lock: > > > > up->port.irqflags |= IRQF_SHARED; > > spin_lock_irqsave(&port->lock, flags); > > if (up->port.irqflags & IRQF_SHARED) > > disable_irq_nosync(port->irq); > > Yup, this looks suspicious. We set a flag in port.irqflags and take the lock > only when the flag was set. Either everything needs to be done under > the lock or the lock is not needed. > > Well, I might have missed something. I do not fully understand meaning > and relation of all the structures. > > Anyway, I believe that this is a false positive. If I get it correctly > serial8250_do_startup() must be called before the serial port could > be registered as a console. It means that it could not be called > from inside printk(). From my understanding, I'm afraid we are talking about actual deadlock here, not about false positive report. Quoting the original email: : We are trying an S3 suspend stress test and occasionally while : entering S3 we get a console deadlock. [..] > > drivers/tty/serial/8250/8250_port.c | 11 +++++++---- > > 1 file changed, 7 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c > > index d64ca77d9cfa..ad30991e1b3b 100644 > > --- a/drivers/tty/serial/8250/8250_port.c > > +++ b/drivers/tty/serial/8250/8250_port.c > > @@ -2275,6 +2275,11 @@ int serial8250_do_startup(struct uart_port *port) > > > > if (port->irq && !(up->port.flags & UPF_NO_THRE_TEST)) { > > unsigned char iir1; > > + bool irq_shared = up->port.irqflags & IRQF_SHARED; > > + > > + if (irq_shared) > > + disable_irq_nosync(port->irq); > > + > > /* > > * Test for UARTs that do not reassert THRE when the > > * transmitter is idle and the interrupt has already > > @@ -2284,8 +2289,6 @@ int serial8250_do_startup(struct uart_port *port) > > * allow register changes to become visible. > > */ > > spin_lock_irqsave(&port->lock, flags); > > - if (up->port.irqflags & IRQF_SHARED) > > - disable_irq_nosync(port->irq); > > > > wait_for_xmitr(up, UART_LSR_THRE); > > serial_port_out_sync(port, UART_IER, UART_IER_THRI); > > @@ -2297,9 +2300,9 @@ int serial8250_do_startup(struct uart_port *port) > > iir = serial_port_in(port, UART_IIR); > > serial_port_out(port, UART_IER, 0); > > > > - if (port->irqflags & IRQF_SHARED) > > - enable_irq(port->irq); > > spin_unlock_irqrestore(&port->lock, flags); > > + if (irq_shared) > > + enable_irq(port->irq); > > > > /* > > * If the interrupt is not reasserted, or we otherwise > > I think that it might be safe but I am not 100% sure, sigh. Yeah, I'm not 100%, but I'd give it a try. -ss