On Thu, Aug 22, 2024 at 08:39:19AM -0600, Keith Busch wrote: > On Thu, Aug 22, 2024 at 03:22:35PM +0800, Tao Su wrote: > > On Tue, Aug 20, 2024 at 04:04:31PM -0700, Keith Busch wrote: > > > + if (map == 1 && !v) > > > + return avx_0f_table[ctxt->b]; > > > + return (struct opcode){.flags = NotImpl}; > > > > Can we check whether the host supports AVX? I.e. if the host does not support > > AVX, set NotImpl. I am thinking that if the host does not support AVX, perhaps > > the guest executing AVX instructions will cause the host to panic, because the > > host will execute AVX instructions during the simulation. > > > > Yeah if the host does not support AVX, it may not report AVX to the guest, but > > the guest can always ignore the AVX check, such as the code in the commit. > > That's a good thought. Here is how I rationalized not adding additional > checks for it: > > If the guest cpu doesn't support AVX, I think it should fail then and > there rather than trap to the hypervisor running on the host, so this > new code wouldn't get a chance to attempt emulating it. > Per SDM: If YMM state management is not enabled by an operating systems, Intel AVX instructions will #UD regardless of CPUID.1:ECX.AVX[bit 28]. Host and guest can set different xstates, so it has possibility to trigger, i.e. host clears but guest sets XCR0[2]. But I don’t see this case can occur now, so just ignore my concern if no one else wants to do that :-) > In the case where the host doesn't support AVX, but the guest does > support it, then I assume the VM is running on an emulated CPU and not > using kvm acceleration anymore. > > Anyway, I haven't tried it, so not entirely confident that's how this > all works. I was mainly following the existing SSE emulations, which > don't have CPU support checks either. I don't think it's a problem to > add such checks though, so happy to do it if needed.