From patchwork Tue Dec 10 23:36:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolei Wang X-Patchwork-Id: 13902459 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29EE51DC9B9 for ; Tue, 10 Dec 2024 23:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.178.238 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733873843; cv=fail; b=Mu7zQOA7/16Ii+Zibgt8QukJAiYZD0jYGZ2EtgkbjkrDhssejsFB8xrJdONrAkg2G1QY5J2NM8RtrEwZEPckFdT5T9jKtrmzZa0UJITvAy/QZqYC3790PcOag/4MXKFM08MPBBVGll+dwcXDg3ofY1muAI+aPbjVo/CPUG4xrKs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733873843; c=relaxed/simple; bh=4b2FYWcZH/9j2f/0CF1IvDGO5jhHfaDTDgraPYfKRFM=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=Q8a6W7rpKmHvRxYWi6IB8fEyRtQnO5Jm4Xftqxxc6jWp1/CxQfrRkJcE8iNc7TRxhsB84/y1xBWJD4Z9XPkCXc+Mm3B1ab7sIGkRQQrUrKPXdCn4wMfph+VTNlzNU34o8SY8YZss4YmTVwPP1R90PcwSIhFLL6ekAOIJEO99AHM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com; spf=pass smtp.mailfrom=windriver.com; arc=fail smtp.client-ip=205.220.178.238 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=windriver.com Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4BAHhb3u005554; Tue, 10 Dec 2024 23:36:39 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2045.outbound.protection.outlook.com [104.47.70.45]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 43cwy3kgnf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Dec 2024 23:36:38 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WqdbMJnHco1rGsOw65WrKWo+llH84eCX7GEgUDNbgqrR4A+rDP/KmpstwxBoTfPNXlO0PI5HTdyDA1jszrqdCzCPtFQ0OuXsMRC+7+VeeHfViRGXlz8TeS+KH+qGXX9vbNRCdY842MbvyviBrhCXLMroDPs8M3QMqdbfoiuSRuQC8TyLtZHJCjdqsn4jOyX4vKGRLXtQeezZtH25jgaCtAR5TI2FSPtvts7D4ZqwkjGE4yHf2dDPUKMg7EeCiRp5+kbTTwIj+miObTfsty64rt8fr7sA8k9y858iR/WcOnBLmM563DfKyrrDOHOGfoGn9Iu7WU/DRxWMY7yVWnSn1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Y1E0+uIMwr90c6wyu3dMpH/74kw0d7Pg4ChP3iwymAI=; b=c5wMwtGfd6uom7Uujhm/6DqfHR2gSJhkY7A573Mp7Z7e08qnSkn4aIebSaTTYIHuZfHHWyFEKHkFpScvcQuqAxTmHdq4EXH/pE5hBCNWWZypKC4YSHEj0zQ/IH5QohGfafzI8ANa685JOCa8uumxGPH+vRXw3BQY/ueDlzbeAc49O11gQnymbmbzP5CIzbqACrNjwebymqvC/sf0RcdWvcrYst12PzcENcj5oj+lAb8DTIBilvSlxPzn6SfbEZl7oRvQYI2zejVka9UNtxHExxQOwP7GL7jEs4l2BhWhn20kL3bzVpIS/I+vqZiA2QnB5bQBoHAvIq0gnYi3YViphQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from MW5PR11MB5764.namprd11.prod.outlook.com (2603:10b6:303:197::8) by CH0PR11MB5284.namprd11.prod.outlook.com (2603:10b6:610:bf::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Tue, 10 Dec 2024 23:36:35 +0000 Received: from MW5PR11MB5764.namprd11.prod.outlook.com ([fe80::3c2c:a17f:2516:4dc8]) by MW5PR11MB5764.namprd11.prod.outlook.com ([fe80::3c2c:a17f:2516:4dc8%7]) with mapi id 15.20.8230.010; Tue, 10 Dec 2024 23:36:35 +0000 From: Xiaolei Wang To: l.stach@pengutronix.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, esben@geanix.com, marex@denx.de, ilpo.jarvinen@linux.intel.com, linux@rasmusvillemoes.dk, stefan.eichenberger@toradex.com, l.sanfilippo@kunbus.com, cniedermaier@dh-electronics.com, rickaran@axis.com, xiaolei.wang@windriver.com Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock() Date: Wed, 11 Dec 2024 07:36:13 +0800 Message-Id: <20241210233613.2881264-1-xiaolei.wang@windriver.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: SG2PR02CA0064.apcprd02.prod.outlook.com (2603:1096:4:54::28) To MW5PR11MB5764.namprd11.prod.outlook.com (2603:10b6:303:197::8) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW5PR11MB5764:EE_|CH0PR11MB5284:EE_ X-MS-Office365-Filtering-Correlation-Id: e55a7377-2e87-4ca7-ea99-08dd19737c3e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|52116014|1800799024|38350700014|7053199007|921020; X-Microsoft-Antispam-Message-Info: BDQg1l12bBJs9E0F+0hAS6E/toJwFFAOAGPOCW6z3bB+8SFHe+Vb1wsCFs8AFcFXn9Ue1IzZ1U+RaDce6tSopa5V3XJX0/ftf+/hOdivrIbvZZD5zDOQ70eVC232xn1/ieu0ZDeUaPp4j5DGvXAWVEKWulKW4rYaE68GqIoI0+qoOLvigDvLIwIbXhWCeN7IkcqxHBv9rJA0DNNcv2NYo4IXuuUfUNPjpPJvoAdG7/f10BBrO94en288D+Xld1IdgEJds+G4O0OxC7iUflgYCva//z9pLKDPNiJixq7JPwZVF+pAHoo954WuhlmEtAIsBJbryiNJY1d9avYNNwa3RIUDOm5T4vRAk5+ppbj78Df76bgoQ5wAQs9KSPQuuIzilvgB+IYWisbllgResOBDli/FsOi9z60btW6mUVTVJF5nQHYFiIfSNuk++AQK3omoH3qwJ6T5ISD02xpj1/S7g+SzdERHTb1pzCP+auCRbvuKg2bhNTot0DtGbMEgy8igjKxOXMerEvci5yOnZhWyfw/h6bHVlRZsvK3Dy1DwsTxPwomqRutv7sQEBwteXGJlIhmLxjZmg8NF2w6I4TGh93X/BvDYwnaS0clsOqvOtelPccGYz23x38o2MNJhPy9zyAtEx0eQ8ekofPG4PxLTq/3nlYRIg3g/PovcT5+7AA2QbVwSj45Hrsk5Zyd+YRs+ib7xTtHdTUk7fub3pbmB1sih1vAIk9MuvQabnr4kiTOgjiEvIi0IypKDQhSPYGe2qQNIfZ+hy4ueHcMyALzF3AJeTLcMlcG1gFRuZ9bH9/SIjemMWpJrPbLt5DrrdU7VUevMGDWmbtU26gp4Y6/c09aVeNWgtUph60WwasAAWx49uhESYZbplsOgdok6fM7sfZTYx+5s9Q+ZkKcrwAd/o78D3aVshUHySpCiyLxPLXDneFZlWGLOiXRIuKYY+Nv09IPqqK35IvX9wjrpBa+HT5WMlN19j2KORPmsSqpagg3GufjdhunPST2YMvOpN7UE5xSS1glGKG/EoA9zaJan9mx0hwFfgNANA1YfZJeBryncfVn6UdiI0MZtdow1utEc+obmjm0hyuN2PyHLc8Y2uQd7DBhCjxW8SfsV0v+BwH6Z+mjtgNY68rDrNcLwJkRUBaRLAKsKZFqT870UPRmYgJ8NVDlxfthD+Yfb0g6xv5dx8taXfEx5+PmzSs4oYHoeKPe/CdZOn2V17oukt9NOxac3QwIFkyp3CYJj/CEoqqxzP2Zd6oD7pHNv7cxbzlx+Cz5chCn8wnpINTmBC/sl/HS8Fqi8LD4IByriFiC42lu/Tjg1dutfpRjrl/9rpnXp2ENkjduPswK4Ffq3Wz/v80R6oXeQx9LBIySlA7gaLPyQEetpFuNU6y4tWUgH8d6IWYw2PICN7xIM1SmWzB0DvV9LnebES1WZFL/kCGX2CAM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW5PR11MB5764.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(52116014)(1800799024)(38350700014)(7053199007)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gcXFon8SUKe31bHxMW9hp9JradQWd/KQQ9bUGfpjczVqq/jFLGBrWT3dMqvZvFOsqMgw9b5iSiazo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CTj5Y8pAdOkspB2mjXO4DyoOg+4rDMDSWNFA80wwP2P4Qob7BrcTq81rymxOsomr+O1I1yX9l0DYpEjHoXKJ7XtxWYVgS2/BQEo4P3lTN3+UN0XiDW6U8A4xNgoo1rkyJFnvG+WU6p1QN9Ps6Tp0mcKSHtDDsGtJqkxRp/gg564LwB2YhGQKvLBQ88S5KAhRl32VR5a67jDGjSEuFcV8wi9aFaIrZg4q8JvMTaS6AqT0RXCsbzKSX/rQB3yIfDCYaCyqGeY6gt8sBFG0TD9O8EJDcjW9vBEddrm+WafzHqbhNuQ4KdAiN9+yCCOqc1DG5snaS9EkyYWMENCRihEX/FG77dy4iAJPzABmqOv1fFake6a0IOWeelSCoGD4Mw4hjms4APySwKF58FtcnQgqkQlSvJlEXKXnvZYTAMwbhP73GZLFGgw1bdBacQ5mR8QRHOyXDDWb3qlCcZ6b55KOzeG2LA== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: e55a7377-2e87-4ca7-ea99-08dd19737c3e X-MS-Exchange-CrossTenant-AuthSource: MW5PR11MB5764.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 23:36:35.4604 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Hg3P1WYVLuuoe/1mOhiQsVc1hrubDeVeW5ODXNDfT+pmpQprsk0yof8OeHT/ng05BNyuB89y8MoyNyjP+DJXA03I7yHrJrXOPD32EWAb/I8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5284 X-Proofpoint-GUID: Gv-fkUBtERz3WJyB__ZYQekhBN1LyqMY X-Proofpoint-ORIG-GUID: Gv-fkUBtERz3WJyB__ZYQekhBN1LyqMY X-Authority-Analysis: v=2.4 cv=D7O9KuRj c=1 sm=1 tr=0 ts=6758d086 cx=c_pps a=WCFCujto17ieNoiWBJjljg==:117 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=RZcAm9yDv7YA:10 a=bRTqI5nwn0kA:10 a=VwQbUJbxAAAA:8 a=t7CeM3EgAAAA:8 a=pGLkceISAAAA:8 a=A__u6bYh_LbSektZ6DAA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-10_13,2024-12-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 priorityscore=1501 mlxscore=0 impostorscore=0 phishscore=0 clxscore=1015 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.21.0-2411120000 definitions=main-2412100169 When executing 'echo mem > /sys/power/state', the following deadlock occurs. Since there is output during the serial port entering the suspend process, the suspend will be interrupted, resulting in the nesting of locks. Therefore, use uart_port_lock_irq() instead of uart_port_unlock(). WARNING: inconsistent lock state 6.12.0-rc2-00002-g3c199ed5bd64-dirty #23 Not tainted -------------------------------- inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage. sh/494 [HC0[0]:SC0[0]:HE1:SE1] takes: c4db5850 (&port_lock_key){?.-.}-{3:3}, at: imx_uart_enable_wakeup+0x14/0x254 {IN-HARDIRQ-W} state was registered at: lock_acquire+0x104/0x348 _raw_spin_lock+0x48/0x84 imx_uart_int+0x14/0x4dc __handle_irq_event_percpu+0xac/0x2fc handle_irq_event_percpu+0xc/0x40 handle_irq_event+0x38/0x8c handle_fasteoi_irq+0xb4/0x1b8 handle_irq_desc+0x1c/0x2c gic_handle_irq+0x6c/0xa0 generic_handle_arch_irq+0x2c/0x64 call_with_stack+0x18/0x20 __irq_svc+0x9c/0xbc _raw_spin_unlock_irqrestore+0x2c/0x48 uart_write+0xd8/0x3a0 do_output_char+0x1a8/0x1e4 n_tty_write+0x224/0x440 file_tty_write.constprop.0+0x124/0x250 do_iter_readv_writev+0x100/0x1e0 vfs_writev+0xc4/0x448 do_writev+0x68/0xf8 ret_fast_syscall+0x0/0x1c irq event stamp: 31593 hardirqs last enabled at (31593): [] _raw_spin_unlock_irqrestore+0x44/0x48 hardirqs last disabled at (31592): [] clk_enable_lock+0x60/0x120 softirqs last enabled at (30334): [] handle_softirqs+0x2cc/0x478 softirqs last disabled at (30325): [] __irq_exit_rcu+0x120/0x15c other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&port_lock_key); lock(&port_lock_key); Fixes: 3c199ed5bd64 ("serial: imx: Grab port lock in imx_uart_enable_wakeup()") Signed-off-by: Xiaolei Wang Reviewed-by: Lucas Stach Reviewed-by: Fabio Estevam --- v1: https://patchwork.kernel.org/project/linux-arm-kernel/patch/20241209124732.693834-1-xiaolei.wang@windriver.com/ v2: use uart_port_lock_irq() instead of uart_port_lock_irqsave() v3: update commit log 'ehco --> echo' drivers/tty/serial/imx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 17f70e4bee43..9c59ec128bb4 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -2692,7 +2692,7 @@ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on) { u32 ucr3; - uart_port_lock(&sport->port); + uart_port_lock_irq(&sport->port); ucr3 = imx_uart_readl(sport, UCR3); if (on) { @@ -2714,7 +2714,7 @@ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on) imx_uart_writel(sport, ucr1, UCR1); } - uart_port_unlock(&sport->port); + uart_port_unlock_irq(&sport->port); } static int imx_uart_suspend_noirq(struct device *dev)