From patchwork Tue Dec 10 03:42:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolei Wang X-Patchwork-Id: 13900821 Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.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 99FB81CEACB for ; Tue, 10 Dec 2024 03:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.166.238 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733802224; cv=fail; b=dYnZf8vW7DKUn6XEzoPeRkltDB3V2auY/lx1tZvR/4ZRob0kcI3l1oj6QxN8FXi1Fx3HZ3+W+Q29nv9kDzpFtTXVs1Kpvd1NK5xb/K+pgOXa9BrQrFZXLVaG0WfhoSFfSVadvrudUj95nDiH09Ny3rY06i+JXtQSGTI4k4wvgPo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733802224; c=relaxed/simple; bh=5FWXVz4brmyeCv61k3vyQoKWTGtFeLowSlKeBYy3dhA=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=qf5nSnDyC0TGIp7Jni+rjFzo6OIxzzU+9XHKoZ4Agpk4bSqmvUN/fNZ2n1oyCTgKiQSnLVlYqxOVqviSBjqru2rl8ha87cXzYbBboxKDx/ic8vcx7qoj1/SC+BsHsdCIWCwCurgDZYVqVlfMajydwheZVpV6L5KJse9x72ZbZ04= 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.166.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 (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4BA3UXuF026669; Mon, 9 Dec 2024 19:42:47 -0800 Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2040.outbound.protection.outlook.com [104.47.51.40]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 43cx1u289c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2024 19:42:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t8FxJ7lnvZCr1lhLVNXZV5NFH+T40tGOOlmQOXK/f1vIUm0suTRU22bj0mPLbkeN0oHQ8hQYSa6L+gdi5Q0JIgb8MSTHoixVu/6bXLM3ruIMyF/a0R4Hkueso4ZLOUyHL1FNDONVCV56UKQqpVqpU4MBPg6QOfkY89LPrUZu6ZrROrLX0ZxDJUtDjdbN3JCtlgkDE07D1ASJNDGrVwLDm/QMOEi39LImeeP0JfU7y+O8dzNAcE4P/SD4OhIwMdNScjI7czWnIzA6a7GIDATSZF0STsquazbhVPTeqSo2w7r7iPUeNT0VPSv9brNguv6/snkKKhWCQPHd6r1mS12Npw== 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=Aw++dKLPg9Vgms+SjHL6am0G8l2+BsA4sCRbdXZcATM=; b=Xizao6MeJ5++wM+3Uu+SPmRMieyZUyjxRcg4pZVpKRnt7PMHRzJ5X2Ha6l4AkE8DG9b1igAyNUebbYq3eia6LmLrjICAXjr2eVhDtMpecmAVHeIK0u65AC8eKu1YG6407xo+RSUQxQyY4AQSJHLJLXB1q6Z1cl6/xs9RLRVW6ty1IndrnhLcFuu41bIUU6w0fWZ8/HW2DkkAhyQ7IvqpMGnreeSvU1WgUZ1YXtCZqRtwy+PZkMRClABih61Ikaprm1QnbpI0Cm0bHwqNxIDfpSPgSwSWnzfctnNJBPxEnvLPfISCadCb8qZKqKpUyu4lQGLEmlquEeY/NO23Bql0Xg== 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 MW4PR11MB6981.namprd11.prod.outlook.com (2603:10b6:303:229::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Tue, 10 Dec 2024 03:42:42 +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 03:42:42 +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 v2] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock() Date: Tue, 10 Dec 2024 11:42:23 +0800 Message-Id: <20241210034223.1493522-1-xiaolei.wang@windriver.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: SG2PR02CA0069.apcprd02.prod.outlook.com (2603:1096:4:54::33) 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_|MW4PR11MB6981:EE_ X-MS-Office365-Filtering-Correlation-Id: a5580fa6-d24c-4769-2448-08dd18ccb38e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|52116014|7416014|376014|921020|38350700014; X-Microsoft-Antispam-Message-Info: t7Bi4LaC0OnStBgas5f7efVe8Tp7j09HE/qWuFXa/DdqTs9PTVowVt1+fMHgnotBCFlP/fCuGEhc+EYyD0jKw1k0S3dDTYwFuUkkoOcHjetimjvyUouQYsxFNeK6sYVQUlAWsPfducwnrfjedI5exafzWGCi8XenC0FUAMAaMhD/GZGwi0POYh8n1P3Jzl11nFXiKgKAq4Ra39nkXwqrXLiXsCfHPzJQ2f+FwE+xsGk//1CvTxYFfpHD4RljF+WD253db/4ykskIqESX40yQ7PMXj2AqLfB16nun/WD+545Z2VFlPixEtKoUq376/TPZRuNDrTpe6tVo9Rl66q3qs15pGnrDrMzmQwBTD52mbQuslDN0XUUPBg24vPhkTTzZ+V3+PpMYiCAF1N98QjmbmkQiyfjBN2I2mBSQspRR5w9UYa0jsfwgGUiGOad8w3PM4e38HnlW3CDbZqCG5gIiNjVT1fvl5HOWcwAFuivaXNuZ/5jArXy54LJM75kj3hrxPAnx1W318dQIjy3VnmOpg1AzkCVEMpiue/P21s8W9LcRYsLWLkmrZLTaMHCFK6CkEOQPRa+2D8TvxvrUJfRdI3v1QjZ+T7Llxcg4KwJIZCSHRbpSErMxAXS7gHMbJ7LX65nctwf+Pb3YzReUT5w6R8mmp3pNB0AUNttr8ZCevNeetZa2Qpps5oJVjYZSvRM6HOSyd1yi+c6oFe8M+TetwSOgrl/3Q21v3f0d5ZSw9t02RNE8kWXcjQeBSE5KwrQf40UyGiZ8dJvdPGLf0BUr/agE0aV9zjgWSD0uOSJ9Jvx8kO26WeRG9BGJdPgnqtrAH2VTTyHce7uXMOKOpILsTgtUFARgkOtAQO6S+FZAzKhOXywwf2UAfbMn7SpPi4I3O3MNWbEKSB9V6IyL6LI59Ygnmyi2zQh01VBwNnK1xWKmGmnkvgSBLHlWin3tNPIRQhfO1O2s0PUEYlpDtJU/omXjln1eKTdb/PxCqUFOzw05WcRhHlklsbwmj39XzP1YYdvD9vd10CtU7U4AOG/RiaQFSDNYqvyi9SfggE7YK5q3VzAIv8PmzFG4Q3Ht9Vjl96Q5InEbJOf9/QN4HaAV1mDPa2SL376EbtuGz3aUBRcRyq/5ooMY6ScYa58By1z3NJk/+CBfGVONYY5c/4iydWWis67zIvYbEQmvkagT/lkRb+Q3BnhxUodS0fNP3bc+HsniLYBJjZouwwIiBEzyUhNXpvAQFj3M/nszdiTMv3oBj+nMbPfuTFkmv+lluY75L39s16zJRsyGB3kBC7tDLuxkNuH07sCI198ArTWjassfc7GS4T2AkS9icWYKh9BdqYt2Sx0KfK/zZgAcYJticOcyDpxf2m0GmzR7NKKlTkaIyhjAtIhtA83rOYUJhTIjOwhFa5jlsjFo8MXrJvzzenInBSViLWfrdlGj89KVIi8= 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)(366016)(1800799024)(52116014)(7416014)(376014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qBj1pwrYqBcooE3zOo0BlnbOASqk/YeLM46pfV/GlVewBr0AMEhxeaE4wnxnq8YqDRGf5TgN7o0n+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QfPaEumj5l0/SIYYqF7dT5SjzHYnp1WV1q0K8yK0KlsOKPzJpYzah5V8E7qLPUv+7prRQeGBaFz0wkGdijSjiQMk5pdwWiXZUfXPN26USINb9dyQiTclmmiZxEYjY1BppJCiW2M2bLcIg9sNHx63YPIB3STgaWqq35nD7W6HgnpsF7fZGipI/xfxk9giaWfJWqCz6lH26vXE4W1WCqqIVGfHVnTyRPQGd5avmv2QUXsF3xJ3yuK/mUWWrCSAITJmUMhg8MWFmtY7qq4hwHgqpB7tuTUnZm99bPXV/2hTYrrus1KN/n6QZGxbi3Gq10/696FWbTu96CUzF0zdWlENsLZfPnj5fOwNW5OOGIcxU1U+95gjX4wnYpQUhh87Rbj++P5r0LV7qq+Vm8vfRS7WliafbQiCQcS9qX5ieTveAn5AVcQKTYTIGHnkjQuJB4R9aAvyw== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: a5580fa6-d24c-4769-2448-08dd18ccb38e X-MS-Exchange-CrossTenant-AuthSource: MW5PR11MB5764.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 03:42:42.3837 (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: wlyk7uEAQMohN/QxQZIqXJUUDtai7bRyPJYQIC9UYQpB73eKdI7tHlqPJDeDYPTFxNBc+3UP96qQxXZDdecS6UAlBFuuNYUkrTn/pSqeKIU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR11MB6981 X-Authority-Analysis: v=2.4 cv=H/shw/Yi c=1 sm=1 tr=0 ts=6757b8b7 cx=c_pps a=UtaLnOzkojfj4BVWksq/2g==: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=A__u6bYh_LbSektZ6DAA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-ORIG-GUID: 7FjK5ft-tOoluzcFAOCOEAlfM8ex3ziY X-Proofpoint-GUID: 7FjK5ft-tOoluzcFAOCOEAlfM8ex3ziY 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-09_22,2024-12-09_05,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 clxscore=1011 impostorscore=0 adultscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.21.0-2411120000 definitions=main-2412100025 When executing 'ehco 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() 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)