* [PATCH v2 2/2] gpiolib: cdev: Fix &le->wait.lock deadlock issue
@ 2023-06-26 10:40 YE Chengfeng
0 siblings, 0 replies; 2+ messages in thread
From: YE Chengfeng @ 2023-06-26 10:40 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, andy; +Cc: linux-gpio, linux-kernel
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 <cyeaa@connect.ust.hk>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH v2 2/2] gpiolib: cdev: Fix &le->wait.lock deadlock issue
2023-06-26 14:57 [PATCH v2 1/2] gpiolib: cdev: Fix &lr->wait.lock " Chengfeng Ye
@ 2023-06-26 14:57 ` Chengfeng Ye
0 siblings, 0 replies; 2+ messages in thread
From: Chengfeng Ye @ 2023-06-26 14:57 UTC (permalink / raw)
To: linus.walleij, brgl, andy; +Cc: linux-gpio, linux-kernel, cyeaa, Chengfeng Ye
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-26 14:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26 10:40 [PATCH v2 2/2] gpiolib: cdev: Fix &le->wait.lock deadlock issue YE Chengfeng
2023-06-26 14:57 [PATCH v2 1/2] gpiolib: cdev: Fix &lr->wait.lock " Chengfeng Ye
2023-06-26 14:57 ` [PATCH v2 2/2] gpiolib: cdev: Fix &le->wait.lock " Chengfeng Ye
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).