Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E89EC636CC for ; Tue, 7 Feb 2023 04:07:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230238AbjBGEHO (ORCPT ); Mon, 6 Feb 2023 23:07:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbjBGEHM (ORCPT ); Mon, 6 Feb 2023 23:07:12 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id A66B6193C2 for ; Mon, 6 Feb 2023 20:07:10 -0800 (PST) Received: (qmail 682275 invoked by uid 1000); 6 Feb 2023 23:07:09 -0500 Date: Mon, 6 Feb 2023 23:07:09 -0500 From: Alan Stern To: Zhongjie Zhu Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] USB: core: hub: fix usb_hub worker blocking drain_all_pages() worker issue Message-ID: References: <20230203072819.3408-1-zhongjiezhu1@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 07, 2023 at 10:02:51AM +0800, Zhongjie Zhu wrote: > On Mon, Feb 6, 2023 at 11:17 PM Alan Stern wrote: > > > > On Mon, Feb 06, 2023 at 11:33:15AM +0800, 朱忠杰 wrote: > > > Yes, this is a very special case. > > > > > > It will happen only when disconnecting the mass storage if there are > > > too many files in the storage, and the scanning operation is running, > > > and the file system is not unmounted. > > > It looks like this issue should be fixed in the usb mass storage > > > driver, but I don't find an appropriate place. > > > > That's not surprising, because usb-storage doesn't know anything about > > what's happening on the mass-storage device it connects to. All it does > > is send the commands that it gets from the SCSI subsystem to the device > > and receive the results back. It has no idea whether there is a mounted > > filesystem on the device, if the filesystem contains any files, or > > whether a scanning operation is running, > > > > A better place to look for fixing this might be the filesystem code. > > That's where the information about mounting, files, and scanning can be > > found. > > > > Alan Stern > > The problem is there is a for loop in the invalidate_inodes(), this > function is in the block device driver. when the usb_disconnect is > called, the filesystem is not umounted, userspace applications will be > noticed the usb storage is disconnected, and then do the umounting > work. > the invalidate_inodes() is called in the usb hub worker, and will run > for a long time. To fix this issue, the long running loop need to be > moved out from the usb hub worker. Oh, maybe I didn't understand. You've got a USB mass-storage device with a mounted filesystem and a lot of dirty inodes, right? Then a USB disconnect happens, and as part of the disconnect processing, invalidate_inodes() runs for a long time. Do you know why it takes so long? The I/O operations shouldn't need any time; they will all fail immediately because the device has been disconnected and so there is no way to communicate with it. Alan Stern