On Tue, Apr 22, 2025 at 10:22:54AM -0700, Sean Christopherson wrote:
Because I really hate wagging the dog and "fixing" the kernel because something else can't be bothered. I didn't object stronger to that fix because it is meh, more of those "if I'm a guest" gunk which we sprinkle nowadays and that's apparently not that awful-ish...
FWIW, I think splattering X86_FEATURE_HYPERVISOR everywhere is quite awful. There are definitely cases where the kernel needs to know if it's running as a guest, because the behavior of "hardware" fundamentally changes in ways that can't be enumerated otherwise. E.g. that things like the HPET are fully emulated and thus will be prone to significant jitter.
But when it comes to feature enumeration, IMO sprinkling HYPERVISOR everywhere is unnecessary because it's the hypervisor/VMM's responsibility to present a sane model. And I also think it's outright dangerous, because everywhere the kernel does X for bare metal and Y for guest results in reduced test coverage.
E.g. things like syzkaller and other bots will largely be testing the HYPERVISOR code, while humans will largely be testing and using the bare metal code.
All valid points...
At least one case justifies the X86_FEATURE_HYPERVISOR check: microcode loading and we've chewed that topic back then with Xen ad nauseam.
But I'd love to whack as many of such checks as possible.
$ git grep X86_FEATURE_HYPERVISOR | wc -l 60
I think I should start whacking at those and CC you if I'm not sure. It'll be a long-term, low prio thing but it'll be a good cleanup.
Thx.