Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3573998pxb; Mon, 24 Jan 2022 12:33:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWBDb/YpN4cnL5ZMtYu1QHqdLqhgmC335yucQjEK29Amivdi4x3vAt0N1MQ9KgEy6QwVxY X-Received: by 2002:a63:6947:: with SMTP id e68mr5188724pgc.618.1643056427634; Mon, 24 Jan 2022 12:33:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056427; cv=none; d=google.com; s=arc-20160816; b=Wx5IxtdkrmTyjaeU2KPfYZM+XZeFxRlfVpS8pRN/dewBmtQBB26ZSgu7mXF2PXFdkC VV4cmfGyBblnkEPHo5nfE5J2T+u7lUjzKXzv9dCSZ7kK8yCxB/76/IiEzl1SKPnN69Ai yFfNfqmkEFnJiDx6dENq/jzLJo6xV0JhQJAE2Ygxq6liik+NwnQd39UlTpiXc/7ft+5H S6ONSCOd81Prfe8l2qPHHpt5pWVz7bxMtU8gfI/PYDla3qtYpSgkFei301xKHxI2TN9O 23y3r/5+PPfDaqCjgqqyqhWCE8BNtRufUIIx1Km0t6AYP/GhGyt8p83DoD5qbkdI6NQy sDYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yHBAECF7A/s5G/DLpGAOv9MVJ2nk867BTRNdmIfUyHY=; b=HYY/dSvXpl7C9eNQLYXGJZEY0XoUdL1bdgUeRr2ebgv7HQJOllwmtycztCsfxHmbZT 8/Ha+GCZvLNZ7Gzt4wcCglv5tYBX6MAyPL2glxfCTD8+w8kEiBbPdVkL7lHG3m4NfoNd V+wCJJ8LRuDcUFfJtDpx8F7/Gd5relOo7fEL22AOjL8+VAReMEJ1Gu1dmnXbBVw46hDz anbGZi+k3TU9lNKujedmcs61+9ta40CNiYIMu34+t4OqnHZqC3TWWW89C8XVjv3ZTIg/ bVCJomGJDhnMarKZ11bA6TNtW3fGoQu0e8i3DXekDT48v3DO0pfanQZsSSM56jgTPnqp PSOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WgXw+SSD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si14341726pgl.426.2022.01.24.12.33.32; Mon, 24 Jan 2022 12:33:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WgXw+SSD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244620AbiAXTmi (ORCPT + 99 others); Mon, 24 Jan 2022 14:42:38 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:55624 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352225AbiAXTce (ORCPT ); Mon, 24 Jan 2022 14:32:34 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 32B45B8122F; Mon, 24 Jan 2022 19:32:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65705C340E5; Mon, 24 Jan 2022 19:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052747; bh=DAO4tYwqdARcTANi8ZVt/gONjK/k/ESqgOqBbagLP1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WgXw+SSDsuHknmkbFyi5Mr1T7qLubIW7S1AaLkSBVQUVJUNO8AcjApBKQW5M56Uas KowftTt+h273oK+K+6Uqke6Zo3KtfjlPOQR2lb/1ZlPgPgsKUmB2qWj5L5R2wIQ20m 1nVnFc+po7czqQGE+tmQj+FsLHtY4PNOmHt/CaRY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Keeping , Pavankumar Kondeti , Sasha Levin Subject: [PATCH 5.4 160/320] usb: gadget: f_fs: Use stream_open() for endpoint files Date: Mon, 24 Jan 2022 19:42:24 +0100 Message-Id: <20220124183959.083332678@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 mutex. 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 Link: https://lore.kernel.org/r/1636712682-1226-1-git-send-email-quic_pkondeti@quicinc.com 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; ffs_data_opened(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; ffs_data_opened(epfile->ffs); - return 0; + return stream_open(inode, file); } static int ffs_aio_cancel(struct kiocb *kiocb) -- 2.34.1