util: Remove RandAddSeedPerfmon #31124

pull hodlinator wants to merge 1 commits into bitcoin:master from hodlinator:2024/10/rm_RandAddSeedPerfmon changing 3 files +3 −45
  1. hodlinator commented at 11:52 am on October 21, 2024: contributor

    RegQueryValueExA(HKEY_PERFORMANCE_DATA, ...) sometimes hangs bitcoind.exe on Windows during startup, at least on CI.

    We have other sources of entropy to seed randomness with on Windows, so should be alright removing this. Might resurrect if less drastic fix is found.

    Hopefully sufficient to fix #30390.

    CI debugged with temporary Windows stack trace dumping + Symbols in #30956.

  2. DrahtBot commented at 11:52 am on October 21, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK fanquake, hebasto, laanwj, achow101
    Concept ACK sipa

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. DrahtBot added the label Utils/log/libs on Oct 21, 2024
  4. hodlinator commented at 12:03 pm on October 21, 2024: contributor

    For brief context, in 3 of 3 checked Windows stack dumps, the main callstack where it hangs has been:

     0 	ntdll.dll!NtReleaseSemaphore()	Unknown
     1 	KERNELBASE.dll!ReleaseSemaphore()	Unknown
     2 	WmiApRpl.dll!WmiReverseGuard::LeaveRead(long)	Unknown
     3 	WmiApRpl.dll!WmiReverseMemoryExt<class WmiReverseGuard>::Read(void *,unsigned long,unsigned long *,unsigned long)	Unknown
     4 	WmiApRpl.dll!WmiAdapterWrapper::GetValidity(unsigned long)	Unknown
     5 	WmiApRpl.dll!WmiAdapterWrapper::CollectObjects(unsigned short const *,void * *,unsigned long *,unsigned long *)	Unknown
     6 	WmiApRpl.dll!WmiAdapterWrapper::Collect(unsigned short const *,void * *,unsigned long *,unsigned long *)	Unknown
     7 	WmiApRpl.dll!WmiCollectPerfData(unsigned short const *,void * *,unsigned long *,unsigned long *)	Unknown
     8 	advapi32.dll!CallExtObj()	Unknown
     9 	advapi32.dll!QueryV1Provider()	Unknown
    10 	advapi32.dll!QueryExtensibleData()	Unknown
    11 	advapi32.dll!PerfRegQueryValueEx()	Unknown
    12 	advapi32.dll!PerfRegQueryValue()	Unknown
    13 	KERNELBASE.dll!BaseRegQueryValueInternal()	Unknown
    14>	KERNELBASE.dll!RegQueryValueExA()	Unknown
    15 	bitcoind.exe!`anonymous namespace'::RandAddSeedPerfmon(CSHA512 & hasher) Line 86	C++
    16 	bitcoind.exe!RandAddDynamicEnv(CSHA512 & hasher) Line 235	C++
    17 	bitcoind.exe!`anonymous namespace'::SeedStartup(CSHA512 & hasher, `anonymous-namespace'::RNGState & rng) Line 624	C++
    18 	bitcoind.exe!`anonymous namespace'::ProcRand(unsigned char * out, int num, `anonymous-namespace'::RNGLevel level, bool always_use_real_rng) Line 662	C++
    19 	[Inline Frame] bitcoind.exe!kernel::Context::{ctor}::__l2::<lambda_1>::operator()() Line 21	C++
    20 	[Inline Frame] bitcoind.exe!std::invoke(kernel::Context::{ctor}::__l2::<lambda_1> &&) Line 1704	C++
    21 	bitcoind.exe!std::call_once<`kernel::Context::Context'::`2'::<lambda_1>>(std::once_flag & _Once, kernel::Context::{ctor}::__l2::<lambda_1> && _Fx) Line 103	C++
    22 	bitcoind.exe!kernel::Context::Context() Line 23	C++
    23 	[Inline Frame] bitcoind.exe!std::make_unique() Line 3597	C++
    24 	bitcoind.exe!AppInit(node::NodeContext & node) Line 188	C++
    25 	bitcoind.exe!main(int argc, char * * argv) Line 277	C++
    26 	[Inline Frame] bitcoind.exe!invoke_main() Line 78	C++
    27 	bitcoind.exe!__scrt_common_main_seh() Line 288	C++
    28 	kernel32.dll!BaseThreadInitThunk()	Unknown
    29 	ntdll.dll!RtlUserThreadStart()	Unknown
    

    …suggesting some kind of (semaphore-related) deadlock sometimes occurs.

  5. in src/randomenv.cpp:230 in 319bbee40d outdated
    187@@ -227,8 +188,6 @@ void AddAllCPUID(CSHA512& hasher)
    188 
    189 void RandAddDynamicEnv(CSHA512& hasher)
    190 {
    191-    RandAddSeedPerfmon(hasher);
    


    sipa commented at 12:09 pm on October 21, 2024:
    You may want to also modify the “// Dynamic environment data (performance monitoring, …)” line in SeedPeriodic() in random.cpp.

    hodlinator commented at 1:02 pm on October 21, 2024:

    Adjusted in latest push, new comment:

    0// Dynamic environment data (clocks, resource usage, ...)
    
  6. sipa commented at 12:11 pm on October 21, 2024: member
    Concept ACK
  7. fanquake commented at 12:41 pm on October 21, 2024: member
    Concept ACK - can also remove winreg.h.
  8. laanwj commented at 12:59 pm on October 21, 2024: member
    Concept ACK as explained in #30956 (comment) - querying all performance counters has a potentially high overhead for the system. (assuming this is confirmed to actually solve #30390)
  9. hodlinator force-pushed on Oct 21, 2024
  10. hodlinator commented at 1:19 pm on October 21, 2024: contributor
    Thanks! Incorporated feedback so far. Changed my personal master branch back to running a scheduled hourly Windows-only job with dump file generation, now including the fix from this PR: https://github.com/bitcoin/bitcoin/compare/master...hodlinator:bitcoin:master
  11. hodlinator force-pushed on Oct 21, 2024
  12. hodlinator commented at 1:45 pm on October 21, 2024: contributor
    Updated 2 more comments along the lines of #31124 (review) in latest push.
  13. util: Remove RandAddSeedPerfmon
    RegQueryValueExA(HKEY_PERFORMANCE_DATA, ...) sometimes hangs bitcoind.exe on Windows during startup, at least on CI.
    
    We have other sources of entropy to seed randomness with on Windows, so should be alright removing this. Might resurrect if less drastic fix is found.
    9bb92c0e7f
  14. hodlinator force-pushed on Oct 21, 2024
  15. hebasto commented at 8:11 am on October 22, 2024: member
    Concept ACK.
  16. fanquake approved
  17. fanquake commented at 3:55 pm on October 24, 2024: member
    ACK 9bb92c0e7ffe2426b4afb80ddd4b4c96968316b5
  18. DrahtBot requested review from sipa on Oct 24, 2024
  19. DrahtBot requested review from laanwj on Oct 24, 2024
  20. DrahtBot requested review from hebasto on Oct 24, 2024
  21. hebasto approved
  22. hebasto commented at 4:26 pm on October 24, 2024: member
    ACK 9bb92c0e7ffe2426b4afb80ddd4b4c96968316b5, I have reviewed the code and it looks OK.
  23. laanwj approved
  24. laanwj commented at 5:35 pm on October 24, 2024: member
    Code review ACK 9bb92c0e7ffe2426b4afb80ddd4b4c96968316b5
  25. achow101 commented at 10:01 pm on October 24, 2024: member
    ACK 9bb92c0e7ffe2426b4afb80ddd4b4c96968316b5
  26. achow101 merged this on Oct 24, 2024
  27. achow101 closed this on Oct 24, 2024

  28. davidgumberg commented at 6:37 pm on October 26, 2024: contributor

    post-merge utACK https://github.com/bitcoin/bitcoin/pull/31124/commits/9bb92c0e7ffe2426b4afb80ddd4b4c96968316b5

    I inspected the call stacks from the dumps of the failed runs hodlinator caused in Visual Studio and confirmed that the RegQueryValueExA call was responsible for every failure, I imagine that this bug may also be infrequently experienced by real windows users outside of CI.

    I haven’t thought very seriously about what high quality entropy sources are and whether or not we have enough of them on Windows without this performance data, but I’m interested in the potential follow-ups suggested by @hodlinator (https://github.com/bitcoin/bitcoin/pull/30956#issuecomment-2427711698) that reintroduce performance data entropy on Windows.

  29. laanwj commented at 8:57 am on October 27, 2024: member

    I haven’t thought very seriously about what high quality entropy sources are and whether or not we have enough of them on Windows without this performance data

    The high quality OS entropy source on windows is CryptGenRandom, and we use that.

    Not opposed to collecting other ancillary data to mix in, though let’s try to avoid something as crude as pulling data from all drivers and processes on the system.

  30. hodlinator deleted the branch on Oct 29, 2024
  31. hodlinator commented at 9:28 am on October 29, 2024: contributor

    The high quality OS entropy source on windows is CryptGenRandom, and we use that.

    A Microsoft article from 2021 on CryptGenRandom states:

    Important This API is deprecated. New and existing software should start using Cryptography Next Generation APIs. Microsoft may remove this API in future releases.

    So maybe we could create an issue to migrate to a more modern API?

  32. laanwj commented at 10:21 am on October 29, 2024: member
    Yes, it’s deprecated, but IIRC the best compromise for the supported windows version. After #31172 we can switch to a whole slew of more modern APIs for windows.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me