Page MenuHomeFreeBSD

x86/cpu: introduce an optional hook for early
ClosedPublic

Authored by royger on Feb 6 2024, 8:39 AM.
Tags
Referenced Files
Unknown Object (File)
Fri, Jun 14, 2:28 PM
Unknown Object (File)
Thu, May 23, 8:37 PM
Unknown Object (File)
May 10 2024, 6:10 AM
Unknown Object (File)
May 9 2024, 8:09 AM
Unknown Object (File)
Mar 17 2024, 10:00 AM
Unknown Object (File)
Mar 17 2024, 10:00 AM
Unknown Object (File)
Mar 17 2024, 10:00 AM
Unknown Object (File)
Mar 17 2024, 10:00 AM
Subscribers

Details

Summary

Hypervisor detection is done very early on x86, and so can be used to also do
some very early hypervisor related initialization. Such initialization is
required when running as a Xen PVH guest, as for example the PIT needs to be
replaced with an hypervisor based timecounter.

Introduce an optional hook that gets called as part of the early hypervisor
detection.

No functional change intended.

Sponsored by: Cloud Software Group

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

royger requested review of this revision.Feb 6 2024, 8:39 AM
sys/x86/x86/identcpu.c
1434

init_fn should be initialized to NULL.

sys/x86/x86/identcpu.c
1434

Indeed, why doesn't clang raise an error that init_fn is used uninitialized?

sys/x86/x86/identcpu.c
1434

Good question. gcc at least catches it.

Fix possaible use of init_fn uninitialized.

This revision is now accepted and ready to land.Feb 6 2024, 4:16 PM
sys/x86/x86/identcpu.c
1434

That worries me quite a bit TBH, I guess some still build with gcc and would catch those, but it's a PITA for devs that this doesn't get noticed, and that I get to push this to phab for my shame :).

sys/x86/x86/identcpu.c
1434

Looks like we are missing -Wconditional-uninitialized. If I enable it, clang warns about init_fn, but there are quite a few warnings that arise, looks like false positives mostly. Admittedly, the control flow in some functions like acl_nfs4_sync_acl_from_mode_draft() is quite confusing. Fixing all of these in some way will be a lot of work.

I guess someone decided that it is better to hide all of these warnings to avoid obscuring other ones.

kib added inline comments.
sys/x86/x86/identcpu.c
1434

BTW I do think that the warning is false positive, but arguably compiler cannot deduce it.

sys/x86/x86/identcpu.c
1434

Which warning do you mean? Sometimes the warnings are correct, but one gets false positives with many common code patterns in the absence of restrict and const qualifiers.

if (foo != NULL)
    bar = 1;
...
if (foo != NULL)
    if (bar) <--- warning, can be silenced by adding qualifiers to `foo`
        ...
sys/x86/x86/identcpu.c
1434

I mean that init_fn is guaranteed to be initialized there, without initializing it in declaration.

sys/x86/x86/identcpu.c
1434

Not if we don't recognize the hypervisor.