Skip to content

Commit fcf68f3

Browse files
computersforpeacejic23
authored andcommitted
iio: fix sched WARNING "do not call blocking ops when !TASK_RUNNING"
When using CONFIG_DEBUG_ATOMIC_SLEEP, the scheduler nicely points out that we're calling sleeping primitives within the wait_event loop, which means we might clobber the task state: [ 10.831289] do not call blocking ops when !TASK_RUNNING; state=1 set at [<ffffffc00026b610>] [ 10.845531] ------------[ cut here ]------------ [ 10.850161] WARNING: at kernel/sched/core.c:7630 ... [ 12.164333] ---[ end trace 45409966a9a76438 ]--- [ 12.168942] Call trace: [ 12.171391] [<ffffffc00024ed44>] __might_sleep+0x64/0x90 [ 12.176699] [<ffffffc000954774>] mutex_lock_nested+0x50/0x3fc [ 12.182440] [<ffffffc0007b9424>] iio_kfifo_buf_data_available+0x28/0x4c [ 12.189043] [<ffffffc0007b76ac>] iio_buffer_ready+0x60/0xe0 [ 12.194608] [<ffffffc0007b7834>] iio_buffer_read_first_n_outer+0x108/0x1a8 [ 12.201474] [<ffffffc000370d48>] __vfs_read+0x58/0x114 [ 12.206606] [<ffffffc000371740>] vfs_read+0x94/0x118 [ 12.211564] [<ffffffc0003720f8>] SyS_read+0x64/0xb4 [ 12.216436] [<ffffffc000203cb4>] el0_svc_naked+0x24/0x28 To avoid this, we should (a la https://lwn.net/Articles/628628/) use the wait_woken() function, which avoids the nested sleeping while still handling races between waiting / wake-events. Signed-off-by: Brian Norris <briannorris@chromium.org> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> Cc: <Stable@vger.kernel.org> # 3.19+ for introduction of wake_woken Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 522caeb commit fcf68f3

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎drivers/iio/industrialio-buffer.c‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
107107
{
108108
struct iio_dev *indio_dev = filp->private_data;
109109
struct iio_buffer *rb = indio_dev->buffer;
110+
DEFINE_WAIT_FUNC(wait, woken_wake_function);
110111
size_t datum_size;
111112
size_t to_wait;
112113
int ret;
@@ -131,19 +132,29 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
131132
else
132133
to_wait = min_t(size_t, n / datum_size, rb->watermark);
133134

135+
add_wait_queue(&rb->pollq, &wait);
134136
do {
135-
ret = wait_event_interruptible(rb->pollq,
136-
iio_buffer_ready(indio_dev, rb, to_wait, n / datum_size));
137-
if (ret)
138-
return ret;
137+
if (!indio_dev->info) {
138+
ret = -ENODEV;
139+
break;
140+
}
139141

140-
if (!indio_dev->info)
141-
return -ENODEV;
142+
if (!iio_buffer_ready(indio_dev, rb, to_wait, n / datum_size)) {
143+
if (signal_pending(current)) {
144+
ret = -ERESTARTSYS;
145+
break;
146+
}
147+
148+
wait_woken(&wait, TASK_INTERRUPTIBLE,
149+
MAX_SCHEDULE_TIMEOUT);
150+
continue;
151+
}
142152

143153
ret = rb->access->read_first_n(rb, n, buf);
144154
if (ret == 0 && (filp->f_flags & O_NONBLOCK))
145155
ret = -EAGAIN;
146156
} while (ret == 0);
157+
remove_wait_queue(&rb->pollq, &wait);
147158

148159
return ret;
149160
}

0 commit comments

Comments
 (0)