KVM guest: Enabling OSXSAVE/AVX

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
gonzo
Posts: 12
Joined: Mon Dec 03, 2018 4:10 pm

KVM guest: Enabling OSXSAVE/AVX

Post by gonzo »

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.
Last edited by gonzo on Sun Feb 21, 2021 2:00 pm, edited 1 time in total.
gonzo
Posts: 12
Joined: Mon Dec 03, 2018 4:10 pm

Re: KVM guest: Enabling OSXSAVE/AVX

Post by gonzo »

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.
Post Reply