Commit 2eb0337
usb: xhci: Fix slot_id resource race conflict
xHC controller may immediately reuse a slot_id after it's disabled,
giving it to a new enumerating device before the xhci driver freed
all resources related to the disabled device.
In such a scenario, device-A with slot_id equal to 1 is disconnecting
while device-B is enumerating, device-B will fail to enumerate in the
follow sequence.
1.[device-A] send disable slot command
2.[device-B] send enable slot command
3.[device-A] disable slot command completed and wakeup waiting thread
4.[device-B] enable slot command completed with slot_id equal to 1 and
wakeup waiting thread
5.[device-B] driver checks that slot_id is still in use (by device-A) in
xhci_alloc_virt_device, and fail to enumerate due to this
conflict
6.[device-A] xhci->devs[slot_id] set to NULL in xhci_free_virt_device
To fix driver's slot_id resources conflict, clear xhci->devs[slot_id] and
xhci->dcbba->dev_context_ptrs[slot_id] pointers in the interrupt context
when disable slot command completes successfully. Simultaneously, adjust
function xhci_free_virt_device to accurately handle device release.
[minor smatch warning and commit message fix -Mathias]
Cc: [email protected]
Fixes: 7faac19 ("xhci: avoid race between disable slot command and host runtime suspend")
Signed-off-by: Weitao Wang <[email protected]>
Signed-off-by: Mathias Nyman <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>1 parent 309b634 commit 2eb0337
File tree
5 files changed
+35
-23
lines changed- drivers/usb/host
5 files changed
+35
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
704 | 704 | | |
705 | 705 | | |
706 | 706 | | |
707 | | - | |
708 | | - | |
| 707 | + | |
709 | 708 | | |
710 | 709 | | |
711 | 710 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
865 | 865 | | |
866 | 866 | | |
867 | 867 | | |
868 | | - | |
| 868 | + | |
| 869 | + | |
869 | 870 | | |
870 | | - | |
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
874 | 874 | | |
875 | | - | |
| 875 | + | |
876 | 876 | | |
877 | 877 | | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | | - | |
882 | | - | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
883 | 882 | | |
884 | 883 | | |
885 | 884 | | |
| |||
920 | 919 | | |
921 | 920 | | |
922 | 921 | | |
923 | | - | |
924 | | - | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
925 | 925 | | |
926 | 926 | | |
927 | 927 | | |
| |||
962 | 962 | | |
963 | 963 | | |
964 | 964 | | |
965 | | - | |
| 965 | + | |
966 | 966 | | |
967 | 967 | | |
968 | 968 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1592 | 1592 | | |
1593 | 1593 | | |
1594 | 1594 | | |
1595 | | - | |
| 1595 | + | |
| 1596 | + | |
1596 | 1597 | | |
1597 | 1598 | | |
1598 | 1599 | | |
| |||
1607 | 1608 | | |
1608 | 1609 | | |
1609 | 1610 | | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
1610 | 1615 | | |
1611 | 1616 | | |
1612 | 1617 | | |
| |||
1856 | 1861 | | |
1857 | 1862 | | |
1858 | 1863 | | |
1859 | | - | |
| 1864 | + | |
1860 | 1865 | | |
1861 | 1866 | | |
1862 | 1867 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3932 | 3932 | | |
3933 | 3933 | | |
3934 | 3934 | | |
3935 | | - | |
3936 | | - | |
| 3935 | + | |
3937 | 3936 | | |
3938 | 3937 | | |
3939 | 3938 | | |
| |||
4090 | 4089 | | |
4091 | 4090 | | |
4092 | 4091 | | |
4093 | | - | |
| 4092 | + | |
4094 | 4093 | | |
4095 | 4094 | | |
4096 | 4095 | | |
| |||
4139 | 4138 | | |
4140 | 4139 | | |
4141 | 4140 | | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
4142 | 4151 | | |
4143 | 4152 | | |
4144 | 4153 | | |
| |||
4245 | 4254 | | |
4246 | 4255 | | |
4247 | 4256 | | |
4248 | | - | |
4249 | | - | |
| 4257 | + | |
4250 | 4258 | | |
4251 | 4259 | | |
4252 | 4260 | | |
| |||
4382 | 4390 | | |
4383 | 4391 | | |
4384 | 4392 | | |
4385 | | - | |
4386 | | - | |
| 4393 | + | |
4387 | 4394 | | |
4388 | 4395 | | |
4389 | 4396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1791 | 1791 | | |
1792 | 1792 | | |
1793 | 1793 | | |
1794 | | - | |
| 1794 | + | |
1795 | 1795 | | |
1796 | 1796 | | |
1797 | 1797 | | |
| |||
1888 | 1888 | | |
1889 | 1889 | | |
1890 | 1890 | | |
| 1891 | + | |
1891 | 1892 | | |
1892 | 1893 | | |
1893 | 1894 | | |
| |||
0 commit comments