Hey guys,
I'm having some trouble enabling AVX in my KVM guest. Once I set OSXSAVE in CR4 it refuses to run the guest. I'm assuming this is something that has to be enabled in other ways. I could enable SSE4.2 just fine. I have written a hardware accelerated CRC32-C function inside the guest and tested it, and it works just fine.
I tried setting XCR0 manually, but it doesn't seem to like that OSXSAVE isn't enabled, so not sure how to proceed.
So, anyone have any experience with the KVM API and how to enable AVX before entering guest? The guest is unprivileged so there will be no enabling there other than feature detection.
KVM guest: Enabling OSXSAVE/AVX
KVM guest: Enabling OSXSAVE/AVX
Last edited by gonzo on Sun Feb 21, 2021 2:00 pm, edited 1 time in total.
Re: KVM guest: Enabling OSXSAVE/AVX
Alright, so I found the solution: You need to query the KVM fd for CPUID features, and then assign that to the guest vCPU. When you do that, you can detect and get host features, like AVX.
First use the KVM_GET_SUPPORTED_CPUID ioctl, followed by KVM_SET_CPUID2 on the vcpu with the resulting features.
First use the KVM_GET_SUPPORTED_CPUID ioctl, followed by KVM_SET_CPUID2 on the vcpu with the resulting features.