Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2103891rda; Tue, 24 Oct 2023 12:23:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdV3ypU5BCVDHp0LVrRBsnYS+wBv3SMdC1BptHA6QkVFZ/NpRKNS6j7tnHTsYmk7dxfiDm X-Received: by 2002:a05:6359:d1d:b0:168:e3c4:7a55 with SMTP id gp29-20020a0563590d1d00b00168e3c47a55mr5714081rwb.13.1698175424842; Tue, 24 Oct 2023 12:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698175424; cv=none; d=google.com; s=arc-20160816; b=h2S8D4BVadzdiHmhc5/l/7kXr8o373X+YKqk7AoQF9q4oWhNGk+Rb2Jjkr7hHUNyFG ngv4rcgiAWC3qwc9dskn7K7mRHik26MCcaQoy2lYp6IBoqggWk0oB+v5YkOh6Ihxogg3 14JkpF6vv0tySOxAMEfE6urGXSjcA2vV5yopeSVqyd6ksAZslsz4KTzU+EfSP2idPyB4 OlStrwnEoeNO6gAlcKU/o0HSOQ//9aEEUdZFuipQs6Hv65TtPhFTCkQBtoWhDQrR4KPA PO5JefvGfdReRzGHt13qRYHWtspxaMipDP1iy5PxIrsn8OsyX9uOSK+zjr8OTggVliYq mzcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=CK8dRUb1zvd0j89Gcn9c1/jjISx0NAwF87His/080EM=; fh=R7bZq2w8c5xv2AD1vfXo0jgdy9ffThbPPPFLhY5prN8=; b=yJlQeOLtQcXkHNv+S351gaJRVWq8l7mgdhvB39HEOL4upxH+OSZfFjdItJ39UiYvXc is/3XQA9huOw5zDWK1FfXAhzsL5cID0Lo9UxG5QAbzDYLC7A/C87LTG2QRLsiFmOU1eE tquIkTHekfSs7orJubP7LthkoL6Rw4ypJVWZhTDCglOa5LDNRQIT/HdaBpx6oybs0SYI X3R3nxp5F1VS2Vaon1LDGnn07PCbnRj2wKi6pX85o8iwiNxeiuCg+Ct9GLykju910Sjs fFPY7huXxHRnXAjHhCZbeOSzMC6VQqGwsfS3I/jpwTIdxqNRwh9U5UcjhBwvK28U0W3R 0EuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id h4-20020a636c04000000b005ace065e52dsi8532059pgc.369.2023.10.24.12.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 12:23:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5F5CA802C924; Tue, 24 Oct 2023 12:23:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344178AbjJXTX1 (ORCPT + 99 others); Tue, 24 Oct 2023 15:23:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343612AbjJXTX1 (ORCPT ); Tue, 24 Oct 2023 15:23:27 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 0C66F10C6 for ; Tue, 24 Oct 2023 12:23:23 -0700 (PDT) Received: (qmail 469860 invoked by uid 1000); 24 Oct 2023 15:23:23 -0400 Date: Tue, 24 Oct 2023 15:23:23 -0400 From: Alan Stern To: "gregkh@linuxfoundation.org" Cc: "Li, Meng" , "linux-usb@vger.kernel.org" , "usb-storage@lists.one-eyed-alien.net" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] usb: storage: add shutdown function for usb storage driver Message-ID: References: <20231023054111.2744872-1-Meng.Li@windriver.com> <33bd0779-bfe7-4c87-8fe6-ea8455df3b6b@rowland.harvard.edu> <3fe5b43c-a5aa-4c6a-8614-03a4d9dd53e2@rowland.harvard.edu> <2023102428-zit-quickness-9b73@gregkh> <5107f6ca-e972-4af1-a21d-6c95778969f3@rowland.harvard.edu> <2023102459-protector-frequency-1033@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2023102459-protector-frequency-1033@gregkh> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 12:23:41 -0700 (PDT) On Tue, Oct 24, 2023 at 07:11:31PM +0200, gregkh@linuxfoundation.org wrote: > On Tue, Oct 24, 2023 at 11:58:37AM -0400, Alan Stern wrote: > > On Tue, Oct 24, 2023 at 05:45:40PM +0200, gregkh@linuxfoundation.org wrote: > > > On Tue, Oct 24, 2023 at 11:35:19AM -0400, Alan Stern wrote: > > > > Okay, that's a different matter. In fact, I don't know what is supposed > > > > to happen during a clean reboot. > > > > > > Define "clean" :) > > > > In this case, I mean what happens when you give the "reboot" command. > > That's a userspace binary/script/whatever that can do loads of different > things not involving the kernel, so it all depends on the user's system > as to what will happen here. > > Many "good" userspace implementation of reboot will go and sync and > unmount all mounted disks in the correct order, before the kernel is > told to reboot. Even if the filesystems are unmounted, the kernel will still probe the drive periodically (once every few seconds) if it claims to have removable media. Failure of those probes won't hurt anything, but it is likely to generate an error message. I don't know if that's what's happening in this case, though. > All we can do in the kernel is act on the reboot system call. > > So perhaps the original poster here can see why his userspace isn't > correctly shutting down their storage devices? Meng, can you do this? Maybe you can fix the problem by adding a script to be executed by the "reboot" command. If the script writes to the "remove" attribute file in the drive's sysfs directory, that will unbind usb-storage from the device. It should give the same result as your patch, for clean reboots. It won't help "reboot -f", though. > > > > What happens with non-USB disk drives? Or other removable devices? > > > > > > It would have to come from "above" in the device tree, so does the PCI > > > or platform bus say that they should be shut down and their child > > > devices? > > > > Well, the PCI layer invokes the HCD's ->shutdown callback. But the > > usb-storage driver and usbcore don't know this has happened, so they > > start logging errors because they are suddenly unable to communicate > > with a USB drive. Meng Li is unhappy about these error messages. > > > > Adding a shutdown callback of sorts to usb-storage allows the driver to > > know that it shouldn't communicate with the drive any more, which > > prevents the error message from appearing. That's what this patch does. > > > > But that's all it does. Basically it creates a layering violation just > > to prevent some error messages from showing up in the system log during > > a shutdown or reboot. The question is whether we want to do this at > > all, and if we do, shouldn't it be handled at the usbcore level rather > > than just within usb-storage? > > We should do this within the usb core if we care about it, but why did > the USB device suddenly go away before the USB storage driver was told > about it? That feels like something else is pulling the power on the > device that is out-of-band here. The device went away because the HCD shut down the host controller, thereby stopping all USB communication. The usb-storage driver wasn't informed because this all happened inside the HCD's PCI ->shutdown callback. HCD shutdown doesn't do anything to the USB bus -- in particular, it doesn't remove the root hub or anything else -- it just turns off the host controller. Since USB class-device drivers don't have ->shutdown callbacks (there is no shutdown() method in struct usb_driver), they don't know what's going on while a shutdown or reboot is in progress. All they see is a bunch of errors. Alan Stern