From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>, Hongyu Xie <xiehongyu1@kylinos.cn>,
Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH v2 04/11] xhci: check device notification type before forwarding wake event
Date: Fri, 9 Oct 2026 18:16:17 +0300 [thread overview]
Message-ID: <20261009151624.618967-5-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20261009151624.618967-1-mathias.nyman@linux.intel.com>
From: Hongyu Xie <xiehongyu1@kylinos.cn>
The xHCI driver programs the Device Notification Control register to
only enable the Function Wake device notification (N1), so any Device
Notification Event TRB received is expected to be a function wake
notification. handle_device_notification() does however not check the
Notification Type field of the event (xHCI 1.2 section 6.4.2.7, DW0
bits 7:4), and forwards every device notification event as a function
wake.
A host controller that delivers an unexpected notification type (e.g.
due to broken firmware or emulation) would trigger a spurious wake
notification on the parent hub.
Parse the notification type and drop events other than Function Wake
with a warning, mirroring the slot ID validation in the same function.
DEV_NOTE_FWAKE is the DNCTRL register bit for notification type 1
(N1), while the event TRB carries the notification type value itself,
so add a separate DEV_NOTE_TYPE_FWAKE constant for the comparison.
[mn:] reduce warning to a debug message
Signed-off-by: Hongyu Xie <xiehongyu1@kylinos.cn>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-ring.c | 9 +++++++++
drivers/usb/host/xhci.h | 5 +++++
2 files changed, 14 insertions(+)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index cbce9f8f07fa..7f480db2983e 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1954,6 +1954,7 @@ static void handle_device_notification(struct xhci_hcd *xhci,
union xhci_trb *event)
{
u32 slot_id;
+ u32 type;
struct usb_device *udev;
slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->generic.field[3]));
@@ -1963,6 +1964,14 @@ static void handle_device_notification(struct xhci_hcd *xhci,
return;
}
+ /* xHCI 1.2 6.4.2.7: Notification Type is DW0 bits 7:4 */
+ type = TRB_TO_DEV_NOTE_TYPE(le32_to_cpu(event->generic.field[0]));
+ if (type != DEV_NOTE_TYPE_FWAKE) {
+ xhci_dbg(xhci, "Unsupported device notification type %u for slot ID %u\n",
+ type, slot_id);
+ return;
+ }
+
xhci_dbg(xhci, "Device Wake Notification event for slot ID %u\n",
slot_id);
udev = xhci->devs[slot_id]->udev;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index c7bfa7f028d3..ec4bfeb4887c 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -187,6 +187,8 @@ struct xhci_op_regs {
* SW does need to pay attention to function wake notifications.
*/
#define DEV_NOTE_FWAKE BIT(1)
+/* Notification Type value carried by a Device Notification Event TRB (6.4.2.7) */
+#define DEV_NOTE_TYPE_FWAKE 1
/* CRCR - Command Ring Control Register - cmd_ring bitmasks */
/* bit 0 - Cycle bit indicates the ownership of the command ring */
@@ -996,6 +998,9 @@ enum xhci_ep_reset_type {
#define TRB_TO_PACKET_TYPE(p) ((p) & 0x1f)
#define TRB_TO_ROOTHUB_PORT(p) (((p) & (0xff << 24)) >> 24)
+/* Device Notification Event TRB fields, 6.4.2.7 */
+#define TRB_TO_DEV_NOTE_TYPE(p) (((p) & (0xf << 4)) >> 4)
+
enum xhci_setup_dev {
SETUP_CONTEXT_ONLY,
SETUP_CONTEXT_ADDRESS,
--
2.43.0
next prev parent reply other threads:[~2026-10-09 15:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 15:16 [PATCH v2 00/11] xhci features and fixes for usb-next Mathias Nyman
2026-10-09 15:16 ` [PATCH v2 01/11] usb: xhci: return an error if the host is not halted Mathias Nyman
2026-10-09 15:24 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 02/11] usb: xhci: Unlock for command abort polling Mathias Nyman
2026-10-09 15:27 ` sashiko-bot
2026-10-10 6:36 ` Michal Pecio
2026-10-09 15:16 ` [PATCH v2 03/11] usb: xhci: fix typos in comments Mathias Nyman
2026-10-09 15:18 ` sashiko-bot
2026-10-09 15:16 ` Mathias Nyman [this message]
2026-10-09 15:23 ` [PATCH v2 04/11] xhci: check device notification type before forwarding wake event sashiko-bot
2026-10-09 15:16 ` [PATCH v2 05/11] xhci: dbc: lock the minor IDR on registration failure Mathias Nyman
2026-10-09 15:25 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 06/11] usb: xhci: Guarantee URB giveback on Ring Underrun/Overrun Mathias Nyman
2026-10-09 15:25 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 07/11] usb: xhci: Don't set the skip flag on non-isoc endpoints Mathias Nyman
2026-10-09 15:23 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 08/11] usb: xhci: Shorten the TD skipping loop Mathias Nyman
2026-10-09 15:22 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 09/11] usb: xhci: Rework and improve the TD matching and skipping logic Mathias Nyman
2026-10-09 15:34 ` sashiko-bot
2026-10-10 6:16 ` Michal Pecio
2026-10-09 15:16 ` [PATCH v2 10/11] usb: xhci: Fix bounce buffer overflow Mathias Nyman
2026-10-09 15:28 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 11/11] xhci: Prevent invalid vdev dereference during sideband unregister Mathias Nyman
2026-10-09 15:30 ` sashiko-bot
2026-10-09 22:47 ` Mathias Nyman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261009151624.618967-5-mathias.nyman@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=xiehongyu1@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.