Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1218217
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: __might_sleep in uio_read()? |
| Date | 2015-09-03 14:30 +0200 |
| Message-ID | <q4BOq-3tf-19@gated-at.bofh.it> (permalink) |
| References | <q4p0S-1T0-23@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed 02-09-15 15:45:10, Andy Grover wrote:
> Hi Hans and Greg,
>
> Is this an issue with uio? I swear it didn't used to throw this warning...
>
> Thanks -- Andy
>
> [ 5174.883261] ------------[ cut here ]------------
> [ 5174.883617] WARNING: CPU: 0 PID: 1532 at
> /home/agrover/git/kernel/kernel/sched/core.c:7389 __might_sleep+0x7d/0x90()
> [ 5174.884407] do not call blocking ops when !TASK_RUNNING; state=1 set at
> [<ffffffffa02a5821>] uio_read+0x91/0x170 [uio]
The warning says that the driver is calling copy_to_user with
TASK_INTERRUPTIBLE which is wrong in general because this context can
sleep and a schedule would destroy the state. It doesn't matter here
because the code would break out from the loop regardless of the
copy_to_user return value.
I assume that TASK_INTERRUPTIBLE is necessary before the event_count
check to prevent from wake up races. If that is the case then you can
simply do:
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 3257d4220d01..7d8959e3833b 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -524,6 +524,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
event_count = atomic_read(&idev->event);
if (event_count != listener->event_count) {
+ __set_current_state(TASK_RUNNING);
if (copy_to_user(buf, &event_count, count))
retval = -EFAULT;
else {
--
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
__might_sleep in uio_read()? Andy Grover <agrover@redhat.com> - 2015-09-03 00:50 +0200
Re: __might_sleep in uio_read()? Greg KH <gregkh@linuxfoundation.org> - 2015-09-03 01:20 +0200
Re: __might_sleep in uio_read()? Michal Hocko <mhocko@kernel.org> - 2015-09-03 14:30 +0200
Re: __might_sleep in uio_read()? Andy Grover <agrover@redhat.com> - 2015-09-03 20:50 +0200
Re: __might_sleep in uio_read()? Greg KH <gregkh@linuxfoundation.org> - 2015-09-03 21:20 +0200
Re: __might_sleep in uio_read()? Andy Grover <agrover@redhat.com> - 2015-09-03 22:20 +0200
Re: __might_sleep in uio_read()? Greg KH <gregkh@linuxfoundation.org> - 2015-09-04 06:00 +0200
Re: __might_sleep in uio_read()? Michal Hocko <mhocko@kernel.org> - 2015-09-04 10:20 +0200
csiph-web