How to enable AVX2 extensions on a Ubuntu guest in VirtualBox 5?

Solution 1:

I was asking myself the same question. I read through major parts of the VirtualBox documentation a while ago and remember that SSE4.1/SSE4.2 is well documented, but AVX2 is not, though it is expected to be exposed to a guest since VirtualBox 5.0 Beta 3.

Here are the flags of /proc/cpuinfo on a 14.04 host:

flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat 
       pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx 
       pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl 
       xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 
       monitor ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 
       sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c 
       rdrand lahf_lm abm ida arat pln pts dtherm tpr_shadow vnmi 
       flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms 
       invpcid xsaveopt

and here on a VM hosted by VirtualBox 5.0.14

flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat 
       pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm 
       constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq 
       ssse3 cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx rdrand 
       hypervisor lahf_lm abm

I searched the Internet and downloaded the source, which brought me to this ticket where frank (Frank Mehnert, I assume) explains how to disable AVX and this ticket noted in the changelog as a reason to disable AVX2 passthrough temporarily as of 5.0.2. So there was a reason to disable it and you should be careful.

I ran VBoxManage setextradata "$vm_name" VBoxInternal/CPUM/IsaExts/AVX2 1, booted my VM and AVX2 was enabled:

flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat 
       pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm 
       constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq 
       ssse3 cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx rdrand 
       hypervisor lahf_lm abm avx2

To check I ran x265 in the VM:

x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 LZCNT

I was looking around if something else could be enabled, grep -r -i "search_term" . in the source did bring up some results for the search terms pIsaExts, pExtFeatureLeaf, pFeatures, pCurLeaf and pCpumCfg but adding keys either had no effect or the VM refused to start. Speaking of which, to view all the extra keys you set run:

VBoxManage getextradata "$vm_name" enumerate

and to delete a key just run the same command you did to set the key but without a value, example:

VBoxManage setextradata "$vm_name" VBoxInternal/CPUM/IsaExts/AVX2

Instead of just grepping through the source it would be better to read and understand the projects' source code organization.