[lkml]   [2022]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Patch in this message
    Subject[PATCH 5.4 160/320] usb: gadget: f_fs: Use stream_open() for endpoint files
    From: Pavankumar Kondeti <>

    [ Upstream commit c76ef96fc00eb398c8fc836b0eb2f82bcc619dc7 ]

    Function fs endpoint file operations are synchronized via an interruptible
    mutex wait. However we see threads that do ep file operations concurrently
    are getting blocked for the mutex lock in __fdget_pos(). This is an
    uninterruptible wait and we see hung task warnings and kernel panic
    if hung_task_panic systcl is enabled if host does not send/receive
    the data for long time.

    The reason for threads getting blocked in __fdget_pos() is due to
    the file position protection introduced by the commit 9c225f2655e3
    ("vfs: atomic f_pos accesses as per POSIX"). Since function fs
    endpoint files does not have the notion of the file position, switch
    to the stream mode. This will bypass the file position mutex and
    threads will be blocked in interruptible state for the function fs

    It should not affects user space as we are only changing the task state
    changes the task state from UNINTERRUPTIBLE to INTERRUPTIBLE while waiting
    for the USB transfers to be finished. However there is a slight change to
    the O_NONBLOCK behavior. Earlier threads that are using O_NONBLOCK are also
    getting blocked inside fdget_pos(). Now they reach to function fs and error
    code is returned. The non blocking behavior is actually honoured now.

    Reviewed-by: John Keeping <>
    Signed-off-by: Pavankumar Kondeti <>
    Signed-off-by: Greg Kroah-Hartman <>
    Signed-off-by: Sasha Levin <>
    drivers/usb/gadget/function/f_fs.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)

    diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
    index 3f5c21f7f9905..2bea33b41553b 100644
    --- a/drivers/usb/gadget/function/f_fs.c
    +++ b/drivers/usb/gadget/function/f_fs.c
    @@ -614,7 +614,7 @@ static int ffs_ep0_open(struct inode *inode, struct file *file)
    file->private_data = ffs;

    - return 0;
    + return stream_open(inode, file);

    static int ffs_ep0_release(struct inode *inode, struct file *file)
    @@ -1156,7 +1156,7 @@ ffs_epfile_open(struct inode *inode, struct file *file)
    file->private_data = epfile;

    - return 0;
    + return stream_open(inode, file);

    static int ffs_aio_cancel(struct kiocb *kiocb)

     \ /
      Last update: 2022-01-24 20:43    [W:2.613 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site