The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Chengfeng Ye <dg573847474@gmail.com>
To: linus.walleij@linaro.org, brgl@bgdev.pl, andy@kernel.org
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	cyeaa@connect.ust.hk, Chengfeng Ye <dg573847474@gmail.com>
Subject: [PATCH v2 2/2] gpiolib: cdev: Fix &le->wait.lock deadlock issue
Date: Mon, 26 Jun 2023 14:57:56 +0000	[thread overview]
Message-ID: <20230626145756.30696-2-dg573847474@gmail.com> (raw)
In-Reply-To: <20230626145756.30696-1-dg573847474@gmail.com>

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 <dg573847474@gmail.com>
---
 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
-- 
2.17.1


  reply	other threads:[~2023-06-26 14:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-26 14:57 [PATCH v2 1/2] gpiolib: cdev: Fix &lr->wait.lock deadlock issue Chengfeng Ye
2023-06-26 14:57 ` Chengfeng Ye [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-06-26 10:40 [PATCH v2 2/2] gpiolib: cdev: Fix &le->wait.lock " YE Chengfeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230626145756.30696-2-dg573847474@gmail.com \
    --to=dg573847474@gmail.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=cyeaa@connect.ust.hk \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox