From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757519AbbICSrh (ORCPT ); Thu, 3 Sep 2015 14:47:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39040 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756843AbbICSrf (ORCPT ); Thu, 3 Sep 2015 14:47:35 -0400 Subject: Re: __might_sleep in uio_read()? To: Michal Hocko References: <55E77BF6.9000109@redhat.com> <20150903122616.GA17976@dhcp22.suse.cz> Cc: hjk@hansjkoch.de, Greg KH , linux-kernel From: Andy Grover Organization: Red Hat Message-ID: <55E895C6.5020305@redhat.com> Date: Thu, 3 Sep 2015 11:47:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20150903122616.GA17976@dhcp22.suse.cz> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/03/2015 05:26 AM, Michal Hocko wrote: > 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 >> [] 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 { > This certainly makes the warning go away. If this looks good to everyone else can we get this change in? Thanks -- Andy