From patchwork Mon Jun 26 10:40:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YE Chengfeng X-Patchwork-Id: 696705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 005F5EB64DC for ; Mon, 26 Jun 2023 10:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229901AbjFZKkH (ORCPT ); Mon, 26 Jun 2023 06:40:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229781AbjFZKkE (ORCPT ); Mon, 26 Jun 2023 06:40:04 -0400 Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on2118.outbound.protection.outlook.com [40.107.114.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CB4EE71; Mon, 26 Jun 2023 03:40:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aN6OjpdUq+FEJeTZip72qZpjZevNJR3Wn66ht8AOl+RQWXepIqd645G6zJvzLHvEFnKFmynca5kG1ViQavigUTExoSlRsPfWkAzSyAob39xUISsoQe+yk6Q+QBnE6CXI1P/HugNPFZeHZ47dv+vK+1kcb9Eukm1bLNhef+YBgIVWrKIFEk7sy1D4sm64e1aN+P4FM6LXWCOAkCofYXqAVM6RTOYhWH0smLHeH/wV83vH7vbG2NpKrh48yBdFQPfyVEB9Gy7o3pRasa0lvgO4pg4PZljkfvOrBzDvhvnDnB4/N84KDoGdsw3sIy2yZ25YSkQ9K00z8B5Y+pECeE5jSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=x6j7rOPN5CMI8cbyRrOChwwaYx6B0vg2J4bGj7BtG1o=; b=RX/Qbp60PrOf/WPByzGGMxfZhxXoFtXXNGTyXPVpLUAvcbxuqSGQ+5b5SLiFL5hwrUfbYzTnvXADW3egbEPCHko7gCE3/tlN+VCpwf/JYLyXkM3UMLTa2R7xViYGR2kKXKZSQMiV9lh/08GODZmz+ITLQjSrT9oqHC/t5OX7rsKFxn3r1JLeiyYbWH8YfnK3Bh0CZlJS/CZ0ktrzSP/aeCkVsi90zBPx5gSyOySLGMhc6y8M1F/yiYp8jo57QSKcsHhBZnAS3dc5tO3ptELSvlGEhQ3lTJjYdIBD+GHsmH77oYjEQO1uu9e+h7NX3mNOcVkuWnHF0I4hHGfwmd/ZOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=connect.ust.hk; dmarc=pass action=none header.from=connect.ust.hk; dkim=pass header.d=connect.ust.hk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=connect.ust.hk; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x6j7rOPN5CMI8cbyRrOChwwaYx6B0vg2J4bGj7BtG1o=; b=AVWZGXFn1LEqj6ILBIeEfU8EPefWrLlPJ8AOFxNUA+BMdDNCGusk5DY11AG0DtXPgPBMTPws2udgoh0lxEljwyZWVO1wiQs8qm/mB5rxPEQyMz+GN6E+tFdVx6kZtSI30xOGZl7mf4TC4yvByLVj6D0ocZtaO0l7RxBEYo0Yv1o= Received: from TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:b7::8) by TYCP286MB1730.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:187::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Mon, 26 Jun 2023 10:40:01 +0000 Received: from TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM ([fe80::b429:5aa3:12f1:6b8]) by TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM ([fe80::b429:5aa3:12f1:6b8%4]) with mapi id 15.20.6521.026; Mon, 26 Jun 2023 10:40:01 +0000 From: YE Chengfeng To: Linus Walleij , Bartosz Golaszewski , "andy@kernel.org" CC: "linux-gpio@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH v2 2/2] gpiolib: cdev: Fix &le->wait.lock deadlock issue Thread-Topic: [PATCH v2 2/2] gpiolib: cdev: Fix &le->wait.lock deadlock issue Thread-Index: AQHZqBRmxizNLtHXWE+SgIMBvkENRg== Date: Mon, 26 Jun 2023 10:40:01 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=connect.ust.hk; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: TYCP286MB1188:EE_|TYCP286MB1730:EE_ x-ms-office365-filtering-correlation-id: e15352f2-67b3-486f-5c16-08db7631b1b7 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Dr9nw/jS0l6RiyHxud7Bffx7yCwciiBEBTcC6WoPgDDu7jrKqVcIWUw187PK45W19AwUTgtgfTPXbAEzM09znlg9J+vr+IGddrTQSvxe7D0EUshxwdqSkDItj1FqJo3hFLeUALwEdsSp7zvyyg39KS+7ALxkdub759YA7pxl/LBFnbyARQnKodo+IBKa/lI/AL4ZnJrPvlKbbcHA7VaHotpaolLnGQVgJf/DeVE/F9uLtqqZLJX4g9N+TX6qXiz9So3bfW6urUslnEkMRpAJam5zey5TtMZV3gi3TG61ag4A5g0l4p7lbZgalHoIYe75/5oVTlACii39erFWo/N1ip6s1xiD2SkcUA62Q9qeTb5ufrfq1GFY4S1W5XCydhYfx8nd43ygaYl57NQcSVMHptVz7uvIJtBLgFWVWt01KlQadnshhU3bULsVdouGPQAQilgbuNNcpbPb5+ifMQirepMGXuBdagdvv50zbOUiZe6EpSPNg+MNjLZ6Ftz7hZqsp3CmZrFcEax7QqZmHtHbuascYvAtF6U735Ya7DpJREoD8rCOa1meSHtQ3TiV7qEVcsAEWwU8wvr5tBSyMYQGEVn9V6jVGvx1XF8Iiayc7yEmexDYSBegkMpwT/DI2oMz x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230028)(4636009)(396003)(376002)(366004)(136003)(346002)(39860400002)(451199021)(8676002)(8936002)(66446008)(76116006)(55016003)(66476007)(66556008)(66946007)(41300700001)(786003)(316002)(64756008)(4326008)(6506007)(26005)(9686003)(186003)(478600001)(54906003)(110136005)(7696005)(71200400001)(91956017)(2906002)(52536014)(5660300002)(38070700005)(122000001)(38100700002)(33656002)(86362001)(83380400001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?eucgb2312_cn?b?YnB6MGswQktKUXNiR2E1ZE1S?= =?eucgb2312_cn?b?VElycllTeDJRYy9lWEtpTzhWaEZnbms1aUpyMkhOMEYzaC8xeFA0eWgzTDZvNTVX?= =?eucgb2312_cn?b?Qjl6VXlWaUdoTlBQTko5UU42S1I1OTdLVWo5VEFlSGdaN1dxbjhEZFFQc1JiUlh1?= =?eucgb2312_cn?b?RUxrU1BuZ1B5dW1QVURIVFQ1NmgyTjl4Z3VFU2RoSWtLNmNVTnV2aUszdVM0K1NR?= =?eucgb2312_cn?b?T0dSZFl4R2dWczdiQUpIYnp0a0hZMmN3OTFranl5SWR4OUtV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=?eucgb2312_cn?b?cWJZd0FLeXgxd0JadTdIaHdEbVV4Qnl2YU04MjhpdlJsZmhHUHpBWndsRHY2Qytm?= =?eucgb2312_cn?b?TUZHRmhpcTh1enQwTVh0WjJ0d212WFhsSUZGR1MyNnVack5DQlhuV0RZRU52R21p?= =?eucgb2312_cn?b?TitnSXIwd1dlWUU5aFZQZzFDeDQwSWVaclg3UG5nTEhoUW5hV01qaTlYVlFXaA==?= MIME-Version: 1.0 X-OriginatorOrg: connect.ust.hk X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: e15352f2-67b3-486f-5c16-08db7631b1b7 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jun 2023 10:40:01.0071 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 6c1d4152-39d0-44ca-88d9-b8d6ddca0708 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: uZgpypUOGzXVJihksNLP3l3pSMBAVaUKPLWcErNliMryHZzEQyf9Ao8TADPJQLC2j5IRaguRbwGiLZqFmURECw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCP286MB1730 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The softirq lineevent_irq_thread() could deadlock on &le->wait.lock if it preempts lineevent_read_unlocked() which acquires the same lock but not disable irq. Fix the potential deadlock by spin_lock_irq(). Fixes: dea9c80ee672 ("gpiolib: rework the locking mechanism for lineevent kfifo") Signed-off-by: Chengfeng Ye --- drivers/gpio/gpiolib-cdev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index f768d46bdea7..a2c108f172f2 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -1858,28 +1858,28 @@ static ssize_t lineevent_read_unlocked(struct file *file, char __user *buf, return -EINVAL; do { - spin_lock(&le->wait.lock); + spin_lock_irq(&le->wait.lock); if (kfifo_is_empty(&le->events)) { if (bytes_read) { - spin_unlock(&le->wait.lock); + spin_unlock_irq(&le->wait.lock); return bytes_read; } if (file->f_flags & O_NONBLOCK) { - spin_unlock(&le->wait.lock); + spin_unlock_irq(&le->wait.lock); return -EAGAIN; } - ret = wait_event_interruptible_locked(le->wait, + ret = wait_event_interruptible_locked_irq(le->wait, !kfifo_is_empty(&le->events)); if (ret) { - spin_unlock(&le->wait.lock); + spin_unlock_irq(&le->wait.lock); return ret; } } ret = kfifo_out(&le->events, &ge, 1); - spin_unlock(&le->wait.lock); + spin_unlock_irq(&le->wait.lock); if (ret != 1) { /* * This should never happen - we were holding the lock