Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@DarkFire01
Copy link
Contributor

I tried my best to comment my reasoning for some of these choices in the code so It's a little clear WHY some of these changes are being made.
I was going to spend some more time delving into some of these behaviors but I think it's probably just not worth the effort while there's some strangeness in this PR it DOES however result in a far more stable experience even when testing our drivers against Windows 2003.

Shortly I'm going to start PRing the UCX stack which is a far more clean driver, there's been some conversation a few of the fellow devs have made about desiring to write UCX and then write a USB 2.0 stack based on that. I believe that's a more sane route than continuing trying to bolt on too many hacks onto this one when we have... strong opinions about it's development :D

As such I'm going to propose these 3 patches which START addressing some of these problems enough to fix things.
and a very nasty hack.
Setting NO_KERNEL_LIST_ENTRY_CHECKS for USBHUB and USBPORT and the HCs.
These LIST_ENTRY issues are a lot of where the bugchecks are coming from and are mostly triggered when too many devices get removed during a boot (like removing a mouse, etc or during the UMPNPMGR setup). We should absolutely be leaving these checks in for our drivers and I'm all for re-enabling it when i have time again to sit down and figure out what the fate of USB 2.0 should be but until then I believe we should set this so we can install and debug more pressing things.

JIRA issues:
CORE-18689
CORE-17052
CORE-19773

Testbot runs (Filled in by Devs)

  • KVM x86:
  • KVM x64:

@github-actions github-actions bot added the drivers Kernel mode drivers and frameworks label Nov 8, 2025
@DarkFire01
Copy link
Contributor Author

Uhh the CORE-18689 number isn't right. Ill look at what the real jira ticket is later

@binarymaster binarymaster added enhancement For PRs with an enhancement/new feature. bugfix For bugfix PRs. labels Nov 8, 2025
@HBelusca
Copy link
Contributor

HBelusca commented Nov 9, 2025

These LIST_ENTRY issues are a lot of where the bugchecks are coming from and are mostly triggered when too many devices get removed during a boot (like removing a mouse, etc or during the UMPNPMGR setup). We should absolutely be leaving these checks in for our drivers and I'm all for re-enabling it when i have time again to sit down and figure out what the fate of USB 2.0 should be but until then I believe we should set this so we can install and debug more pressing things.

This naively sounds like some of the lists (or say, structures in which the list heads are present) not being locked correctly, and when there are these many device removals, timing issues arise where the lists are being acted upon concurrently and become corrupted.

guid.c
usbehci.rc)

target_compile_definitions(usbehci
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe needs to be marked as "HACK" (+ same in the other cmakelists)


/*
* Multiple port change bits can be set at once (e.g. enable + reset).
* Handle each independently
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Handle each independently
* Handle each independently.

* I'm not convinced this is actually what windows is doing.
* It's possible the issue is in the lower driver.
*/
return Status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto ExitError;
}

/* Mark USB2 hub flag when identifiable (bDeviceClass available in header). */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* Mark USB2 hub flag when identifiable (bDeviceClass available in header). */
/* Mark USB2 hub flag when identifiable (bDeviceClass available in header) */

TransferedLen);
}

/* Use the known bMaxPacketSize0 (was obtained prior to SetAddress). */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* Use the known bMaxPacketSize0 (was obtained prior to SetAddress). */
/* Use the known bMaxPacketSize0 (was obtained prior to SetAddress) */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes you have me remove periods like this comment or add them like above, I'm confused on what you actually want here. What are you trying to do?

Copy link
Contributor

@HBelusca HBelusca Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here my "logic" was:

  1. Single-line single sentence comment -- no dot;
  2. Two or more sentences -- all sentences end with dot (even if they are all on the same single line).
  3. Multi-line comment (with single or more sentences) -- all sentences end with dot.

Just a preference, there's nothing as such in our code style, so do as you personally prefer.

}

if (Port == 0 ||
Port > PdoExtension->RootHubDescriptors->Descriptor.bNumberOfPorts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not Port >= PdoExtension->RootHubDescriptors->Descriptor.bNumberOfPorts instead?
Or is Port a 1-based value?

Feature = SetupPacket->wValue.W;

if (Port == 0 ||
Port > PdoExtension->RootHubDescriptors->Descriptor.bNumberOfPorts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question

Context->cbw.Flags = ((UCHAR)Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) << 1;
Context->cbw.LUN = PDODeviceExtension->LUN;

// Per BOT spec, LUN is 4 bits; clamp just in case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BOT == Bulk Only Transfer ?

*
* TODO: There's actually a bigger bug here though,
* while the above CAN HAPPPEN:
* Card Readers multiplex their card slots for example But we can deal with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Card Readers multiplex their card slots for example But we can deal with
* Card Readers multiplex their card slots for example, but we can deal with

// check that we're sending to the right LUN
ASSERT(SrbGetCdb(Request)->CDB10.LogicalUnitNumber == PDODeviceExtension->LUN);
/*
* Some stacks/devices don’t propagate the LUN in the CDB10 header bits.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they don't propagate the LUN in the CDB10 header, then what does the CDB10.LogicalUnitNumber member contain in that case? a random value? 0xFFFFFFFF ? or 0 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix For bugfix PRs. drivers Kernel mode drivers and frameworks enhancement For PRs with an enhancement/new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants