Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3618873pxb; Mon, 24 Jan 2022 13:39:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpZ6jeMxgY0ZO7jOC3lJQEXklWCZFeOtq2IYhc6j4zflWQhbykAys96J9QqrPlLDhUGnS7 X-Received: by 2002:a63:88c7:: with SMTP id l190mr13328265pgd.155.1643060242211; Mon, 24 Jan 2022 13:37:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643060242; cv=none; d=google.com; s=arc-20160816; b=ScnKnAdOYsTNYk2TwPyzoTs3f8n/sOOvmZrfkRJh+IehOejPyjZBBUcFzSOp7AWD3i iuzeNedvpbR6EYWSaJ01OK8H34EtfF3bdK7l8pHtyehDhXTqAZ36pXQQK6zAJuBI3yyY RKKnYOZHhsnzs6iuheVKwRWOG4xb0Kf2uYBQ5pgT6QNvdA8HvLkqodb1YrnYMjHLMcid 3Td1QnqRvfiqURY2EfgmDqpzv8AxPpNKpWJHNuFaQc1r1tuBpjlu6l0UefwQymrMyxgs RETNsxiLwJmhDCMbEBDCxkhXmHMn/f/rL0Av+CPLArf4yzLp1lutMZ3WX3uMHRIX9/A3 oPIQ== 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=jYAQ7rjd+u1vbJ/GUuy5ZGa1qchmpIATc7/dcm1skeI=; b=rt6QV8vijmpeB8DSMUlenF6HdDsEWvmBIvXg+dpNqqC477XHinQ3kH9F2JO5YGSB3Q zkYyjjL3H7MQACjdkLfKYXgMy6KyufI56ZG3m37tBwBTxTBkInEPxrXYxi0KwB1GAxnn Mns4rJ+jSXgcqvgvVhdDuNOAWi38qYJYL4BYFmD0qSWRusDu/QQoRI0nhxPqH6lkPVc6 d7uJWwg7+Li0egryTljloEz+7IqLtkrXUDXrnNlvWOiXqkUk7N2CS7GGlLcQna6rBQBB bGP/p5jxpjfr7zpmzf9i6J7b0e6ssbe0K0PzL7EByT5ODfaenRv8WWJh/2j7yGpDf5Rf v3bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SxWaDOXi; 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 rm9si424849pjb.26.2022.01.24.13.37.10; Mon, 24 Jan 2022 13:37:22 -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=SxWaDOXi; 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 S1448779AbiAXVNr (ORCPT + 99 others); Mon, 24 Jan 2022 16:13:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391105AbiAXUq7 (ORCPT ); Mon, 24 Jan 2022 15:46:59 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E72EC0619C2; Mon, 24 Jan 2022 11:56:52 -0800 (PST) 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 3AB33B8122F; Mon, 24 Jan 2022 19:56:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92510C340E5; Mon, 24 Jan 2022 19:56:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643054210; bh=WwyqKVvqSWpzPHuY0DjZnnFLbWkXOccjBFegE6a5n8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SxWaDOXibv/qmdAVtyEesNJeWeMRve9vQnfLf+F3cxcSwNvOKXLCnLoG+TJL6E+Up 1SUGSDwWQF+2GKCF//MgeqNRtoQgfCuigzR8uoPje/Nds6C90Rw3rt/9TVhBLhyT6y 7D2cqq4jW2vgCMcrZF1iR/QZYzenn4QPoYLxzFzM= 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.10 313/563] usb: gadget: f_fs: Use stream_open() for endpoint files Date: Mon, 24 Jan 2022 19:41:18 +0100 Message-Id: <20220124184035.255603480@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@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 cbb7947f366f9..d8652321e15e9 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) @@ -1152,7 +1152,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