From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796299502; b=m6mlUvpJ5jOglzqe3Gd+CyM3f+AnoqFu/QOA7ejILTaE3RBMGvgH6ojeBeIbt+G+6Rhi E+WSOrFeAu1FNQEo41Eb+pPIdMd4ZpexeQ/Ju3ArG7Di4GDNJEf8g/22w1xNKv2G0+cvr c3H1yL5LFa6S8v/M49saBd88BKeKLJwlRsQDq4B4m7Xx5PmTDfYLobyaHn9AFrmbYrEMW xDNFlfFsOhn5+pvRNsc4qRH72aOa10jE3AhlU95SN0SZ3CwzarjAahvi4DZpSNGLwAa0B Wr4uquZEYTxzjE24tSpEgHn/oOq25XmfQjZGMo9wllYfKeqcths9NHDfZSaKblbJ/1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796299502; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type:X-Mailer: Content-Transfer-Encoding; bh=WCIQAzfZxk+3wH9rDl/boTJuHKegfsbvJfOLIy6r3VI=; b=aUPylzYAVNHWFHQ0ukUCdgpf9wRbwWEpto5RPnpJA3sYRNQYbPazGYYGGzLThuv8Z0QQ qB+75+3Y9WfcTAyVWpiMQHCBdqNXU9615OOjcMKNlFEI/uFLWYzehOq5WGjDnrm95dLDV pAcCU+02Fd244+nN+uUnp+8MMfV5jjE0e7JJlBfwJV5BiQJq6/ejyO0p8xe21gZxAUqkr uJYVfbmvO1sQnnd8CZ8o5qk4R7nuCm4sZHmKJYKdOtNvzvGowXhcUmy6g8hZB1eLHBjEt toL5lCMNUJqXBmK7TOSAObrg94zNGnDto0QoaQI7jYW+usH3CXfUL5004+79Pd6yvhg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=C2n90U1A; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAA36606FD30; Thu, 3 Dec 2026 12:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=C2n90U1A Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB8D61F00893; Thu, 3 Dec 2026 12:05:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796299502; bh=WCIQAzfZxk+3wH9rDl/boTJuHKegfsbvJfOLIy6r3VI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C2n90U1AUiI/sEEZ27PzEDEVM+KRe+k/4ShjZebkJYAXcEPfiYKo5bPYDd2wZwFzm TRhih5m846lP8IBIFQFHm95/9xw0sifCciZ8BSu6HJMySqdtaUc9//kKJL8qHAJrJJ HV1XjlT8zjM1PH8ldCduyRJMPMmecQBiF/mKsG/Pt2+dNYcaWhzBIEA7jqex+s4ShU Q6/+iJA2D6gJkFUa45ASnMaN6xb7F2Mdgm1/x3VsU/YvZQWo0W1C9DxSBU55y9Y58f VXuJGgkyGunz2y93GP2IF833Lzwp0+zyzEOsES/SDQLYXekvm3C0CsqYpuzK3Cv2Xr KZmdnmf5QXIYg== From: Leon Romanovsky To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Dmitry Torokhov , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Johannes Berg , Jonathan Corbet , Shuah Khan , Randy Dunlap , Bjorn Helgaas , "Joerg Roedel (AMD)" , Suravee Suthikulpanit , Vasant Hegde , Will Deacon , Robin Murphy , David Woodhouse , Lu Baolu , Johan Hovold , Eric Dumazet , Marcel Holtmann , Luiz Augusto von Dentz , Nipun Gupta , Nikhil Agarwal , Pieter Jansen van Vuuren , Chris Lu , Mans Rullgard , Alan Stern , Jaroslav Kysela , Takashi Iwai , Andrew Morton , Cornelia Huck , Andrew Morton , Jeff Garzik , "Rafael J. Wysocki" , Bart Van Assche , Alexander Duyck , Dan Williams , Lukas Wunner Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-input@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-usb@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-acpi@vger.kernel.org, linux-doc@vger.kernel.org, linux-pci@vger.kernel.org, iommu@lists.linux.dev, linux-coco@lists.linux.dev, Alexey Kardashevskiy , Luiz Augusto von Dentz , Greg Kroah-Hartman , linux-sound@vger.kernel.org, Jason Gunthorpe Subject: [PATCH v5 20/33] USB: Drain usbfs when a device is unregistered Date: Thu, 3 Dec 2026 14:03:42 +0200 Message-ID: <20261203-device-trust-core-v5-20-485cc6eddd46@nvidia.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203-device-trust-core-v5-0-485cc6eddd46@nvidia.com> References: <20261203-device-trust-core-v5-0-485cc6eddd46@nvidia.com> X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.17-dev-d2b70 Content-Transfer-Encoding: 8bit From: Leon Romanovsky Only the generic USB device driver tells usbfs that a device is gone. A device without that driver bound, such as one unbound through sysfs, is unplugged without any notification. usbdev_open() does not check for a driver, so a process can open such a device and sleep in poll() on its idle descriptor. The unplug never wakes it or sends its disconnect signal. Drain usbfs from usb_disconnect() before device_del(). The device is already marked as not attached, so no new user can open it. The later drain from the generic driver finds nothing left. Fixes: 782da727b0d59 ("usbcore: make usb_generic a usb_device_driver") Signed-off-by: Leon Romanovsky --- drivers/usb/core/devio.c | 4 ++-- drivers/usb/core/hub.c | 3 +++ drivers/usb/core/usb.h | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 1491ba015bcd..a881f06361bf 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -2862,7 +2862,7 @@ const struct file_operations usbdev_file_operations = { .release = usbdev_release, }; -static void usbdev_remove(struct usb_device *udev) +void usbfs_notify_remove(struct usb_device *udev) { struct usb_dev_state *ps; @@ -2889,7 +2889,7 @@ static int usbdev_notify(struct notifier_block *self, case USB_DEVICE_ADD: break; case USB_DEVICE_REMOVE: - usbdev_remove(dev); + usbfs_notify_remove(dev); break; } return NOTIFY_OK; diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 199d3f535a89..372bd6368cc9 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2379,6 +2379,9 @@ void usb_disconnect(struct usb_device **pdev) if (udev->usb4_link) device_link_del(udev->usb4_link); + /* usbfs is otherwise notified only by a bound generic driver */ + usbfs_notify_remove(udev); + /* Unregister the device. The device driver is responsible * for de-configuring the device and invoking the remove-device * notifier chain (used by usbfs and possibly others). diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 1b2de58fd6ce..cbee73183747 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h @@ -195,6 +195,7 @@ extern const struct file_operations usbdev_file_operations; extern int usb_devio_init(void); extern void usb_devio_cleanup(void); +void usbfs_notify_remove(struct usb_device *udev); /* * Firmware specific cookie identifying a port's location. '0' == no location -- 2.56.1