Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6076533ybe; Tue, 17 Sep 2019 19:39:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9L+e7z5kEB8Yc1+Ta8cscuk04zFB/Hg1tAoiMNxpGPTQbwRx1jH4ozdpY0UAMCJaUAeyK X-Received: by 2002:a50:fc18:: with SMTP id i24mr1378882edr.69.1568774343226; Tue, 17 Sep 2019 19:39:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568774343; cv=none; d=google.com; s=arc-20160816; b=vcvNHTcXQc/dZXhyYT1+NpY98dnA9zv1lkt6i6U5vI/do6xeMHZ3sDNL/lS1uNzrGF qecKJG4dzoHQk8avxFdfBOeKapJboRh6t67/aU6+HiqDIvn9CaGTWrzt1M9BKs4qVvx/ Xe2gtXVwXlpEHDBD94/8yoGjPZwzUmfkXaSEtYSjnLPF+5x5i8KoWtLZv0FuHB0Jke9p mdeSUUSDUy1KCSMLRnIBRQwlFKOUVdiU6MTFNKzaSf+zYzzRWBZpMCCfMdp7+IFI1y9O bK9ZFNwmqs3NErPJiEtaQdOfNpHT4OMOS9f/EzG4ZkSEHbZzuVD3Dr4x6ieZQyox75w4 Qo2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=33HTI06KrYihGCLmTdOTJ2bFANdV8foxW+4RD7RD/Xc=; b=bDR+YgRanICrrp4LrNNO/rc8u9PR83+obhQ3u++cFETb4IHf+VtIztOWY/bBqwuftt i3J6caICxXsttGkLuSMu6leGZl3UrszkcWwBztvhghBBZQVu1Fi5xsokQxdZ5GLv6ygO u0fupzBZgouEDTuOZQ8D2SDB/GDJPhCDiOV2WfalW1Er9YscGlT6Y/OxwxMUqB+cetTh njTaZEZ7zmoDiDV81qU1pOluUOmj65oC3mWaUlmkMxpBTDI+DA/HWnYoPvIj9YShx6xL sCoXmubFed9XDK0kV50KYOw6s+c/99ILckAWS/+lS5p/Jljt+pFbChM3QXzVRBU4HkEU c8oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DwaEKlPK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id oq3si2231189ejb.220.2019.09.17.19.38.39; Tue, 17 Sep 2019 19:39:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DwaEKlPK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728655AbfIRBah (ORCPT + 99 others); Tue, 17 Sep 2019 21:30:37 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40714 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728628AbfIRBah (ORCPT ); Tue, 17 Sep 2019 21:30:37 -0400 Received: by mail-pl1-f195.google.com with SMTP id d22so2335651pll.7 for ; Tue, 17 Sep 2019 18:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=33HTI06KrYihGCLmTdOTJ2bFANdV8foxW+4RD7RD/Xc=; b=DwaEKlPKJqyulqtleaOqVOomI2ti3y98zNUKheFHpcFrLoD0VpS3UXXrXKkemIkxX8 uiC7GHehMljmtwdBglEjtPEX3MsNehgqWJMJRBJYw97NlR92bfad1bh0w3hNmoVjJyZ3 MkRvKjEGoWHdJtl/ci8dN2+mRw/Hy/qlnxTuIhnHC1Aivy0x+v+Ma5fuz/5LQrMT99d/ uzvR5TKacwSgrS+JFBmY1qhkYkH4YWSP7a86Xd5wZ07SRHLzNXYJf6INfeQOdjYFl4kW rRb+EHxh3FFSmya+PmRa1ureN94iSctc0FhNUnnutYCgY60zS05juBvCaxAgNxPe/Zhr dvyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=33HTI06KrYihGCLmTdOTJ2bFANdV8foxW+4RD7RD/Xc=; b=ODxqDRvuCgqy86Cr6i0XDFYz1mseA+4NPOXv46D24TKhxOMDZrxtSJaJOzYYGMqdQu 7pAYDysfm+fFhVcSHUspZoPDug+XnVEWCizWTy5vTJFzlDXwTPrCZ5tGyjNOAt8pLrmL +oChmQ9J8OgMpL/GzqXEu+mj/TT6e1TwS4E1aF1B4qOOA7D1vyJApITJ4dr7Y7D1G6h9 UJN5CQvKwtp1GSodQyb17CbD34WMX+inr357RDZRX2A8cmCdEymf1kpwzREHytjQNLiy pQxdELuZncUkP0OMj9acEEsNvr3sSPF9ku1Wns9zCrKD2RemahXtD8XYIzJWjdxi+OqO wvfQ== X-Gm-Message-State: APjAAAX7pWnKCmk9+Xw4bpd8Jn5+F1DzjbSaYjeutbwOB6pFvr6VzC22 fFSUVPUnIyr6rcyhpkrwZgA= X-Received: by 2002:a17:902:aa87:: with SMTP id d7mr1560745plr.203.1568770236125; Tue, 17 Sep 2019 18:30:36 -0700 (PDT) Received: from localhost ([175.223.34.14]) by smtp.gmail.com with ESMTPSA id u7sm3323938pgr.94.2019.09.17.18.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2019 18:30:35 -0700 (PDT) Date: Wed, 18 Sep 2019 10:30:32 +0900 From: Sergey Senozhatsky To: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= Cc: Sergey Senozhatsky , Tetsuo Handa , Steven Rostedt , Petr Mladek , linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: Re: Regression in fd5f7cde1b85 ("printk: Never set console_may_schedule in console_trylock()") Message-ID: <20190918013032.GA2895@jagdpanzerIV> References: <20190917141034.gvjg7bgylqbbxyv7@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190917141034.gvjg7bgylqbbxyv7@pengutronix.de> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (09/17/19 16:10), Uwe Kleine-K?nig wrote: > Hello, > > Today it saw sysrq on an UART driven by drivers/tty/serial/imx.c report > a lockdep issue. Bisecting pointed to > > fd5f7cde1b85 ("printk: Never set console_may_schedule in console_trylock()") Hmmm... I don't see how this patch can affect anything. It simply disables preemption in printk(). > When I type t I get: > > [ 87.940104] sysrq: SysRq : This sysrq operation is disabled. > [ 87.948752] > [ 87.948772] ====================================================== > [ 87.948787] WARNING: possible circular locking dependency detected > [ 87.948798] 4.14.0-12954-gfd5f7cde1b85 #26 Not tainted > [ 87.948813] ------------------------------------------------------ > [ 87.948822] swapper/0 is trying to acquire lock: > [ 87.948829] (console_owner){-...}, at: [] console_unlock+0x110/0x598 > [ 87.948861] > [ 87.948869] but task is already holding lock: > [ 87.948874] (&port_lock_key){-.-.}, at: [] imx_rxint+0x2c/0x290 > [ 87.948902] > [ 87.948911] which lock already depends on the new lock. > [ 87.948917] > [ 87.948923] > [ 87.948932] the existing dependency chain (in reverse order) is: > [ 87.948938] > [ 87.948943] -> #1 (&port_lock_key){-.-.}: > [ 87.948975] _raw_spin_lock_irqsave+0x5c/0x70 > [ 87.948983] imx_console_write+0x138/0x15c > [ 87.948991] console_unlock+0x204/0x598 > [ 87.949000] register_console+0x21c/0x3e8 > [ 87.949008] uart_add_one_port+0x3e4/0x4dc > [ 87.949019] platform_drv_probe+0x3c/0x78 > [ 87.949027] driver_probe_device+0x25c/0x47c > [ 87.949035] __driver_attach+0xec/0x114 > [ 87.949044] bus_for_each_dev+0x80/0xb0 > [ 87.949054] bus_add_driver+0x1d4/0x264 > [ 87.949062] driver_register+0x80/0xfc > [ 87.949069] imx_serial_init+0x28/0x48 > [ 87.949078] do_one_initcall+0x44/0x18c > [ 87.949087] kernel_init_freeable+0x11c/0x1cc > [ 87.949095] kernel_init+0x10/0x114 > [ 87.949103] ret_from_fork+0x14/0x30 This is "normal" locking path console_sem -> port->lock printk() lock console_sem imx_console_write() lock port->lock > [ 87.949113] -> #0 (console_owner){-...}: > [ 87.949145] lock_acquire+0x100/0x23c > [ 87.949154] console_unlock+0x1a4/0x598 > [ 87.949162] vprintk_emit+0x1a4/0x45c > [ 87.949171] vprintk_default+0x28/0x30 > [ 87.949180] printk+0x28/0x38 > [ 87.949189] __handle_sysrq+0x1c4/0x244 > [ 87.949196] imx_rxint+0x258/0x290 > [ 87.949206] imx_int+0x170/0x178 > [ 87.949216] __handle_irq_event_percpu+0x78/0x418 > [ 87.949225] handle_irq_event_percpu+0x24/0x6c > [ 87.949233] handle_irq_event+0x40/0x64 > [ 87.949242] handle_level_irq+0xb4/0x138 > [ 87.949252] generic_handle_irq+0x28/0x3c > [ 87.949261] __handle_domain_irq+0x50/0xb0 > [ 87.949269] avic_handle_irq+0x3c/0x5c > [ 87.949277] __irq_svc+0x6c/0xa4 > [ 87.949287] arch_cpu_idle+0x30/0x40 > [ 87.949297] arch_cpu_idle+0x30/0x40 > [ 87.949305] do_idle+0xa0/0x104 > [ 87.949313] cpu_startup_entry+0x14/0x18 > [ 87.949323] start_kernel+0x30c/0x368 This one is a "reverse" locking path... port->lock -> console_sem There is more to it: imxint() lock port->lock uart_handle_sysrq_char() handle_sysrq() printk() lock conosole_sem imx_console_write() lock port->lock [boom] This path re-enters serial driver. But it doesn't deadlock, because uart_handle_sysrq_char() sets a special flag port->sysrq, and serial consoles are expected to make sure that they don't lock port->lock in this case. Otherwise we will kill the system: void serial_console_write(...) { ... if (sport->port.sysrq) locked = 0; else if (oops_in_progress) locked = spin_trylock_irqsave(&sport->port.lock, flags); else spin_lock_irqsave(&sport->port.lock, flags); ... } So I'd say that lockdep is correct, but there are several hacks which prevent actual deadlock. No idea why bisection has pointed at fd5f7cde1b85, it really doesn't change the locking patterns. -ss